01-14-2015 03:40 AM
Hello,
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?
01-14-2015 07:49 AM
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.
Ignore the name mismatch between the MCL reference and the control itself... the beauty of snippets.
01-14-2015 08:07 AM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks
01-14-2015 08:17 AM
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.
Blog for (mostly LabVIEW) programmers: Tips And Tricks