LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

inserting items into listbox

Hi,
 
  I would like to use a listbox to display log entries for my program.  If the operation is a success the entry would just be normal black text on a white background.  If an error occurred I want the background to go to red with white text.  I know how to do this if I just add the item to the last position in the list but I would like to treat the list like a stack always inserting the last log entry on the top of the stack and pushing the other items down.  On the push down I want the characteristics of the list time to go with it.  So if line 0 was a warning and I put a new entry into 0 pushing the former to line 1 I would expect Line 1 to now show a red background with white text and line 0 would have the appropriate background and text if it is a warning or not.  I am using LV 8.2.1, is this doable?  Is there a better control for this type of operation.
 
Thank you,
 
Bob
0 Kudos
Message 1 of 2
(3,225 Views)
It's doable. You will need to maintain an array of all the lines. When you add a new line, insert it at the beginning of this array. Then, you will need to loop through each element of the listbox (preferrably in reverse) and set the colors to those of the element above it. When you do this, use the "Defer panel updates" property to increase the speed of this operation. Set it to true, loop through the listbox changing colors, then set it back to false.

If this isn't very important, adding the elements to the end will be much simpler. You won't need to insert elements into the front of an array, and you won't have to loop through each element in the listbox every time you add something.

As far as a better control to accomplish this, I'm not sure. Tables, trees, listboxes all have string arrays containing the element names and properties of each cell that don't correspond with each other. Adding elements doesn't preserve the association of the text of a cell with its color characteristics.
Message 2 of 2
(3,216 Views)