LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

ListBox Size

How do you set the size of a List Box?

InsertListItem does not mention it and it states that itemIndex is a zero-bases index into the list and -1 inserts the item at the end of the list.

I am not sure where the end of the list is.

0 Kudos
Message 1 of 5
(3,777 Views)

There is no explicit parameter that defines a listbox size, so I'm assuming that a listbox content is limited by PC memory (I really never used listboxes with more that 3-400 lines, so I suppose I always was far away form this control limits). The end of the list is simply the last line present in the control. If you want update control display so that the last line is always visible (thus faking the behaviour of a DOS window) you may use a code like this:

 

    int        line = 0;

    char    msg[512];

 

    // Prepare your line in 'msg' variable

    InsertListItem (panelHandle, PANEL_LISTBOX, -1, msg, ++line);
    SetCtrlVal (panelHandle, PANEL_LISTBOX, line); ProcessDrawEvents ();
 



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,770 Views)

Thanks Roberto.

 

It is dangerous not know this number and assume you have enough memory.

What I have done is declare an array of strings and that is my list box size.

I use a timer to update the lisbox if anything has changed:

 

 

int CVICALLBACK UpdateListBox (int panel, int control, int event,
  void *callbackData, int eventData1, int eventData2)
{
    int i;
    int first_visible_line = 0;
   
    switch (event)
    {
  case EVENT_TIMER_TICK:

            if (update_display == UPDATE_DISPLAY)
            {
                ClearListCtrl (gPanelHandle, PANEL_LISTBOX);

                for (i=0;i<listbox.num_of_active_rows;i++)
                {
                    InsertListItem (gPanelHandle, PANEL_LISTBOX, i, listbox.row_element[i].item, 0);
                }
               
                if (listbox.num_of_active_rows > NUM_OF_ROWS)
                {
                    first_visible_line = (listbox.num_of_active_rows - NUM_OF_ROWS);
                }

                SetCtrlAttribute (gPanelHandle, PANEL_LISTBOX, ATTR_FIRST_VISIBLE_LINE, first_visible_line);
                update_display = DO_NOT_UPDATE_DISPLAY;
            }
   break;
    }
 return 0;
}
 

  

#define LISTBOXITEMSIZE   100
#define LISTBOXSIZE           100
#define NUM_OF_ROWS      24
       
typedef struct
{
    char item[LISTBOXITEMSIZE];
}ListBoxItem;

 

typedef struct
{
    ListBoxItem row_element[LISTBOXSIZE];
    int num_of_active_rows;
}ListBoxDisplay;       

0 Kudos
Message 3 of 5
(3,755 Views)

While I may agree with your opinion as of the risk of not setting a limit to the listbox size, I respectfully disagree with your implementation, as I note that you are dubling memory usage by creating your messages first in memory and after that in the listbox. Moreover, you are adding a serious overhead on the timer callback (which should be *fast*) by clearing and populating every time the whole listbox.

 

It is better for efficiency to simply add new lines to the listbox (and to your array of strings you want to maintain it) and in case add a simple control on the number of entries in the listbox deleting from the top those in excess and adding to the end of it (you can test GetNumListItems at the beginning of the timer callback and use DeleteListItems to delete only the older <n> elements, maybe a small set of them so that this operation is only executed rarely, depending on the speed you write new lines in the control).

 

But first of all I don't seem to see any real reason to maintain a memory copy of the listbox contents, since you may every time retrieve the desired line(s) by using for example GetLableFromIndex.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 5
(3,748 Views)

I will try what you suggest.

 

Memory usage isn't a concern but the overhead will be.

There will be up to 32 serial comm ports (each with its own list box-9600Baud) Txing canned commands and Rxing responses. The responses have to be searched for string matches and acted upon accoringly for the next Tx command. The list boxs are for displaying the Tx and Rx data in almost real time with a fixed visible size of 24 lines with scroll bars for max 100 lines of scrolling. Once the Rx string is searched it only needs to be in the list box.

 

All serial ports will be operating at the same time with selector buttons to view each list box individually hiding the other ones.

 

My concern is the coms overhead for 32 ports and processing the Rx'd data.

 

Thanks,

Brad.

0 Kudos
Message 5 of 5
(3,746 Views)