LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

multicolumn listbox - scroll to last element

Hello, Smiley Happy

 

I have program that uses listbox to display some messages. When new message is recieveD,it is added as last element into MCL. I want MCL to scroll down so that user can see this message.

I know there is top left property or something like that but mu MCL can have multiline input and it will be resized at runtime so I can't calculate this property.

 

As last resort my solution will be to add new message on top instead of bottom but that is counterintuitive for user....

Does anyone know some way around that?

0 Kudos
Message 1 of 4
(4,441 Views)

This should do what you're asking.  It's setup so that it doesn't make the very last element the only one displayed in the list by simply setting the last element to the top viewable, but rather makes it the last visible one in the list so that the user can have some context as to where they are in the MCL.

 

mcl_display_last.png

 

Ignore the name mismatch between the MCL reference and the control itself... the beauty of snippets.

Message 2 of 4
(4,415 Views)

Drew has hit it exactly right.

 

If N is the number of rows in your data, and NumRows is the number of rows you have allotted on screen, then

 

If N > NumRows                     ;if more data than space

    TopRow = N - NumRows    ;figure Top Row so that last row is at the bottom

else

     TopRow = 0                       ; scroll to top 

end if

 

Set MCL TopRow.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 3 of 4
(4,408 Views)

It might improve the appearance if you were to do it slightly differently.

 

Define your MAX # Rows as the maximum space you can allow on screen:

 

MaxNRows = 10

 

Then compare your data to that, and SET the NumRows property.

 

MCL.NumRows = Min (NRowsInData, MaxNRows)      ;  adjust the size of the listbox to fit the data.

 

MCL.VerticalScrollbarVisible = NRowsInData > MaxNRows   ; show/hide the scrollbar

 

MCL.TopLeft = { max (NRowsInData- MaxNRows, 0) | 0 }    ; scroll to make last item visible

 

 

The idea is that the MCL will be one line tall if there's only one line to show (or none), two lines if there are two lines, ten lines if there are ten, etc.

If there are 11 lines or 111 lines in the data, it will show the last 10, with a scrollbar.

    

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 4
(4,406 Views)