LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

list box index

In the code below I am trying to get the proper iItem in from the control when I single left click on it. There seems to be a delay. ie I left click once, and I get the previous iItem. then I need to left click again (note not double left).
Please tell me what I am doing wrong.

case EVENT_LEFT_CLICK:
SetCtrlAttribute (panelHandle, PANELSCRIP_WEIGHT, ATTR_DIMMED, 0);
iRc=GetCtrlIndex (panelHandle, PANELSCRIP_LISTBOX, &iItem);
iRc=GetLabelFromIndex (panelHandle, PANELSCRIP_LISTBOX, iItem, szValue);
szValue[4]='\0';
iRc = Ini_GetInt (itHandle, "Weights", szValue, &iInt);
if (iRc>0)
SetCtrlVal (panelHandle, PANELSCRIP_WEIGHT, iInt);
else
SetCtrlVal (panelHandle, PANELSCRIP_WEIGHT, 0);

break;
0 Kudos
Message 1 of 4
(3,720 Views)
This behaviour depends on the order on which control events are processed.

Click events on a control are processed before the control changes its value (in case of a list: moves the selecting line), so GetCtrlIndex correctly returns the old selected item index.

To obtain the new item index you must move your code to EVENT_VAL_CHANGED event. Strange enough, the event is triggered even if values associated to the list items are the same: in this case the event seems to be related to the control's index rather then its value.

In case you cannot use EVENT_VAL_CHANGED event, you could use a postdeferred callback to process the event:

In the list callback add these lines:
if (event == EVENT_LEFT_CLICK) {
PostDeferredCall (IndexFunct, 0);

return 0;
}

The post deferred callback:
void CVICALLBACK IndexFunct (void *callbackData)
{
int i;
char msg[32];

GetCtrlIndex (mainH, Main_lista, &i);
sprintf (msg, "Item index %d.", i);
MessagePopup ("Index", msg);
return;
}

Remember that in this case the postdeferred callback is processed after all control events, so you may need to adapt your code.

Hope this helps
Roberto


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?
Message 2 of 4
(3,720 Views)
Roberto, thanks. I have one more issue with it. I have a numeric control on the panel that I have dimmed initially. When a user clicks on any of the the list items, I want to undim it. Now when the list box first comes up, there is a dotted line around the first item. This is fine. Then the user clicks on this first item, and I want the numeric to undim. I have code in

case EVENT_COMMIT:
SetCtrlAttribute (panelHandle, PANELSCRIP_WEIGHT, ATTR_DIMMED, 0);
break;

to undim it. This seems to work fine if the user picks any of the list items except the first one with the dotted lines.
0 Kudos
Message 3 of 4
(3,720 Views)
You've put the undim code in the EVENT_COMMIT of the listbox. Assuming the listbox is not in check mode, commit events are only sent to the callback whenever the user presses the key, or double-clicks on the listbox. From your description, it doesn't seem as if that is what you want. It seems that you'd want to do it on the LEFT_CLICK event, or if that's overkill, maybe on the GOT_FOCUS event.

You should look at the behavior of the listbox events in the user interface editor (switch to operate mode, and look at the top-right corner of the window) to pick the one that best matches your objectives.

Luis
NI
0 Kudos
Message 4 of 4
(3,720 Views)