10-02-2014 02:03 PM
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.
Solved! Go to Solution.
10-03-2014 03:13 AM
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:
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.
10-06-2014 12:01 PM - edited 10-06-2014 12:08 PM
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; }
10-07-2014 09:32 AM
Great solution, jared. This works very nicely for my applicaiton.