04-25-2013 06:31 AM
I want to display a simple messagepopup when the user selects a particular new cell in a table.
I uses the table callback function with the event_active_cell_change.
But with the messagepopup function in my code, the event "event_active_cell_change" is fired twice and thus the messagepopup is displayed twice.
If I just remove from my code the messagepopup function, everything's fine (event fired just ounce).
Any workaround?
Thanks.
Cyrille
Solved! Go to Solution.
04-25-2013 06:45 AM
so your code looks like
switch ( event )
{
case EVENT_AVTIVE_CELL_CHANGE:
MessagePopup ( "title", "message" );
break;
}
? It's always easier to assist with more information
04-25-2013 08:47 AM
Sorry so for the lack of information, no CVI running on my computer.
Anyway you guessed perfectly how my code looks like
Regards.
Cyrille
04-25-2013 09:38 AM - edited 04-25-2013 09:43 AM
OK, so I assume that this is because of the following:
1) The user changes the active cell by clicking on it
2) The callback displays the MessagePopup, due to the popup there is no active cell anymore
3) The popup is closed, hence the cell is active again and the callback is called a second time
You can see this change also in the color of the selected cell, it is highlighted before and after the message popup, but not during the display of the popup.
So as one possible solution you could use a boolean variable that is toggled between 0 and 1: the part of your EVENT_ACTIVE_CELL_CHANGE callback is executed only if your toggle is 0...
switch ( event )
{
case EVENT_AVTIVE_CELL_CHANGE:
if ( !toggle )
{
MessagePopup ( "title", "message" );
}
toggle = !toggle;
break;
}
04-26-2013 09:04 AM
Thanks Wolfgang,
I noticed this behaviour with the highlighted cell (kind of lost focus by the table).
Nevertheless the workaround was a good idea, just difficult to implement in my case, but it works.
Regards.
Cyrille
05-03-2013 08:28 AM
Hi Cyrille,
I just wanted to chime in and say that the behavior you're describing is actually a bug. I've created a bug report for it (405988). This has an implication for your workaround, since at some future time this bug will be fixed and you will stop receiving this event twice. At that time, your current workaround would become invalid, since it would then be incorrect to skip every other event.
I can suggest a different workaround. It's a bit more complicated, but it will work for you both before and after the bug is fixed. It takes advantage of the fact that, with the buggy behavior, the second event is sent immediately after the callback returns, before any other callback can be called:
void CVICALLBACK FlagClearFunc (void *callbackData)
{
*(int *)callbackData = 0;
}
int CVICALLBACK TableCB (int panel, int control, int event, void *callbackData,
int eventData1, int eventData2)
{
static int ignoreNextEvent = 0;
switch (event)
{
case EVENT_ACTIVE_CELL_CHANGE:
if (!ignoreNextEvent)
MessagePopup ( "title", "message" );
ignoreNextEvent = 1;
PostDeferredCall (FlagClearFunc, &ignoreNextEvent);
break;
}
return 0;
}
Sorry about the inconvenience.
Luis
NI
05-03-2013 09:48 AM
Thanks Luis. It works fine.
With the previous workaround I had to add some "toggle=!toggle" elsewhere in my code, because this bug appears only after a click on a new cell but not after a keypress nor a table redrawn.
Anyway thanks a lot.
Cyrille