LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

allow checkbox focus without COMMIT?

Solved!
Go to solution

I have an array of checkbox controls.  Each control has the same callback function which will update a text string, identifying which checkbox was clicked.

 

I would like to give my users the ability to gain the focus of a checkbox control without an EVENT_COMMIT happening.  In other words, it is highly likely that they will do a single click on the control to get the focus there.  But in so doing, they will inadvertently toggle the checkbox value.

 

So my thoughts were to:

 

1) Capture the EVENT_COMMIT and swallow it, or preserve the value and keep the value the same as before the commit.  This doesn't work, as the value changes before the commit even happens.

 

2) Just have the user do a right-click on the control.  With the EVENT_RIGHT_CLICK, I can call the callback again with the EVENT_GOT_FOCUS event.  This works nicely enough, but it's entirely non-intuitive.

 

I guess I'm just looking for some other novel way of doing this.

0 Kudos
Message 1 of 4
(4,972 Views)

Well, this is just the way checkboxes work: regardless you click on the checkboxs itself or its label, the control changes its state from checked to unchecked and vice versa. I see no easy way to overcome this behaviour.

 

Just some idea that come quickly to my mind, whithout having tested them:

  1. Trap EVENT_VAL_CHANGED (as you have already observed in #1, it is fired before the commit event) and swallow it if the active control is another one (it seems consistent that EVENT_GOT_FOCUS is the last one fired).
  2. Add a conformation message for state change if the control is not the active one
  3. Set your checkboxes in indicator mode and trap EVENT_LEFT_CLICK: you could switch clicked control to hot if it's not the active one and switch it back to indicator on EVENT_LOST_FOCUS. A little problem I see is that it seems to me that the lost focus event is not fired on the control if you click on another panel (e.g. click on a tab page while the checkbox is on the main panel: double check this situation as it's just an idea out of my memory).
  4. Replace the checkbox label with a separate text control: if the user clicks on the label you simply issue a SetActiveCtrl to the associated checkbox, while if he clicks on the checkbox he will change the status. The click-twice-to-change caveat is common to all these situation.

All these workarounds have disadvantage that to change the checkbox state you need to click twice on it every time it's not the active one, which could be boring.



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
(4,960 Views)
Solution
Accepted by topic author ElectroLund

If I understand what you're asking, it seems like this would do the trick. In the left click event, check the active control, and if it is different than the control that was clicked on, set the active control to the control that was clicked on and swallow the left click event.

 

int CVICALLBACK CheckboxCB (int panel, int control, int event,
                         void *callbackData, int eventData1, int eventData2)
{
    int swallow = 0;
    switch (event)
    {
        case EVENT_LEFT_CLICK:
            if (GetActiveCtrl(panel) != control)
            {
                SetActiveCtrl(panel, control);
                swallow = 1;
            }
            break;
    }
    return swallow;
}

 

Message 3 of 4
(4,923 Views)

Great solution, jared.  This works very nicely for my applicaiton.

0 Kudos
Message 4 of 4
(4,906 Views)