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