LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Searching through a list control

Problem:
I have a list control that currently has over 6500 lines of text (results of test). I need to search each line of text in the list control for some specific text.

Desired solution:
I would like to be able to index through the list and do the search on each line without affecting the displayed list. It seems however that NI has different plans for use of the list control. As I'm looking through the CVI manual it appears that the only that I can do this is to first select an item (by index) to make it the current item (SetCtrlIndex ()) and then read the value from the control (GetCtrlVal ()). Unless I'm wrong, I believe that the 'SetCtrlIndex ()' will cause the display to be updated, which will really sloooow dow the search process.

Is there another solution that I'm overlooking? I don't want to make the control invisible.

Hurst
0 Kudos
Message 1 of 8
(6,188 Views)
You can use both GetLabelFromIndex and GetValueFromIndex to get the label and value of each entry in the list control based on the index.

Hope this helps,

-alex
0 Kudos
Message 2 of 8
(6,182 Views)
I tried 'GetLabelFromIndex ()' and all it gives me is the value of index + 1 in text string. So this is definitely not what I want.

When I tried 'GetValueFromIndex ()', I get a run-time error complaining about the itemValue (4th arg) argument. I supplied a 'char *' and CVI wants an 'int *'. What ami doing wrong?

Hurst
0 Kudos
Message 3 of 8
(6,177 Views)
Maybe I don't understand what you are trying to do. Every entry in a listbox has two pieces of information: the label (that displays in the control) and the value (which is never visible in the UI but is used to associate data with each element). If you have a listbox and want to get the text of each successive line as a string, then GetLabelFromIndex will allow that. GetValueFromIndex retrieves the hidden value associated with each item (the type of which you can specify, but in your case it seems to be an int). I assume you are not using the value portion and are only interested in the strings in the listbox.

This seems like what you are looking for. Can you get me a bit more detail on what your specific use case?

Thanks,

-alex
0 Kudos
Message 4 of 8
(6,174 Views)
OK, the list ctrl is built using:

char buffer[MAX_STRING];

// Clear the list
ClearListCtrl (gReportPanel, REPORT_REPORT_LIST);
// Insert each line into the report list
for (i = 0; ; i++)
{

o
o
o

// Add it to the list
InsertListItem (gReportPanel, REPORT_REPORT_LIST, -1, buffer, 0);

// If tests are done, terminate loop
if (-----)
break;
}

But after it's been built, I need (in another module) to go through the test results and search for the occurrence of certain strings.
0 Kudos
Message 5 of 8
(6,173 Views)
Hi.

Check out the List... functions in Programmer's Toolbox (see sample project at samples\toolbox\list.prj).

To create a list:

struct
{
...
} myStruct;

ListType myList;

myList = ListCreate (sizeof(myStruct));

You can create a list of structs, with each item in the list storing the details for a single test (time, results, pass/fail etc.) You can search and sort the list as needed. No need to worry about parsing either.

As each test is completed, the results could be stored in both myList and the List Control on your GUI.

Regards,
Colin.
0 Kudos
Message 6 of 8
(6,163 Views)
I made a small example using GetLabelFromIndex to search a listbox with randomly generated strings. Have a look at it and tell me if this technique can suit your needs. Your use case is probably not as interactive as this, but the same approach should be valid.

Regards,

-alex
Message 7 of 8
(6,147 Views)
I found my problem. There were some empty lines entered and what appears in the list box is just a line number. When I was debugging, I just happened to pick these lines and so I saw the index + 1 and jumped to the wrong conclusion. GetLabelFromIndex does exactly what I need, and so everything is working fine now, except now I need to figure out how to get rid of the line numbers.

Hurst
0 Kudos
Message 8 of 8
(6,144 Views)