LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

messagePopup in EVENT_ACTIVE_CELL_CHANGE fires another active_cell_change event

Solved!
Go to solution

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

0 Kudos
Message 1 of 7
(3,140 Views)

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 Smiley Wink

 

0 Kudos
Message 2 of 7
(3,133 Views)

Sorry so for the lack of information, no CVI running on my computer.

Anyway you guessed perfectly how my code looks like Smiley Wink

 

Regards.

Cyrille

 

 

 

 

0 Kudos
Message 3 of 7
(3,126 Views)
Solution
Accepted by topic author cyrille_d

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;

}

 


 

0 Kudos
Message 4 of 7
(3,121 Views)

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

0 Kudos
Message 5 of 7
(3,106 Views)

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

Message 6 of 7
(3,075 Views)

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

 

0 Kudos
Message 7 of 7
(3,065 Views)