LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with Numeric control on Tab Panel

Hi, I'm using CVI 7.1 on Win XP pro. I have defined a new numeric control by using the NewCtrl() function on Tab Cntrl Panel created from canvas control.
I have defined it's type to HOT or VALIDATE, but the value can not be edited. I can only increment/decrement the value. What should I do, please help. The code with a problem is attached.

Thanks, Shimonir
0 Kudos
Message 1 of 7
(4,816 Views)
I can duplicate your problem with CVI 6.0 and Windows 2000.
It appears that controls created by NewCtrl have a problem getting the focus.
In the attached example I have numeric controls on a main panel and on EasyTab panels, some created at design time, some at run-time using NewPanel and NewControl.
The numeric controls created at design time (with the UI Editor) don't have any problem. The controls created at runtime by NewCtrl do have a problem. A NewCtrl on the main panel has less of a problem than a NewCtrl on a EasyTab problem, but they both have problems.
Try the following on the attached sample.
1. Start the program.
2. Click in the control titled "Created at RunTime" on the main panel.
3. Enter a number. Edits work OK.
4. Click in the control titled "Created at RunTime" on the tab labeled "Created at RunTime".
5. Enter a number. Number gets entered into control on the main panel. Control on the EasyTab doesn't really have the focus.
6. Click in the control titled "Created at DesignTime" on the tab labeled "Created at DesignTime".
7. Enter a numnber. Edits work OK.
8. Click in the control titled "Created at RunTime" on the main panel.
9. Enter a number. Number gets entered into control on the EasyTab panel labeled "Created at DesignTime". Control on the main panel doesn't really have the focus.
10. Click in the control titled "Created at DesignTime" on the main panel.
11. Enter a number. Edits work OK.
12. Click in the control titled "Created at RunTime" on the main panel.
13. Enter a number. Edits work OK.
0 Kudos
Message 2 of 7
(4,781 Views)
Here's a work around that works in CVI 6.0.
Since the problem appears to be in a control getting focus, install a callback for the new control and use SetActivePanel and SetActiveControl to force the focus. Next problem: after forcing the focus, the control doesn't see an EVENT_LOST_FOCUS, so the next time back to the control, it doesn't see EVENT_GOT_FOCUS. So force focus on EVENT_LEFT_CLICK or EVENT_GOT_FOCUS.
See the updated sample which installs a callback for the NewCtrl on the tab panel, but not one for the NewCtrl on the main panel. It has a checkbox on the front panel so you can test it forcing focus and not forcing focus.
0 Kudos
Message 3 of 7
(4,771 Views)
Hello shimonir and Al S,

A quick way to resolved the focus issue with the numeric control on the easy tab would be to add the numeric control to the panel before adding the panel to the easy tab.

For instance, using Al S's code, instead of:

EasyTab_AddPanels(hMainPanel, tabCtrl, 1, hNewPanel, 0);
EasyTab_LoadPanels (hMainPanel, tabCtrl2, 1, "NewCtrl.uir", __CVIUserHInst, PANEL_2, &hPanel2, 0);
newControlOnTab = NewCtrl (hNewPanel, CTRL_NUMERIC_LS, "Created at RunTime", 50, 50);
newControlOnMain = NewCtrl (hMainPanel, CTRL_NUMERIC_LS, "Created at RunTime", 220, 15);
. . .

Try:
newControlOnTab = NewCtrl (hNewPanel, CTRL_NUMERIC_LS, "Created at RunTime", 50, 50);
newControlOnMain = NewCtrl (hMainPanel, CTRL_NUMERIC_LS, "Created at RunTime", 220, 15);
...
EasyTab_AddPanels(hMainPanel, tabCtrl, 1, hNewPanel, 0);
EasyTab_LoadPanels (hMainPanel, tabCtrl2, 1, "NewCtrl.uir",__CVIUserHInst, PANEL_2, &hPanel2, 0);

This rearrangement of code seems to resolve the problem shimonir is seeing (if you aren't trying to add a numeric control to the main panel at run time). There is still an issue with the numeric control on the main panel getting focus back (and I am looking further into this).

Hope that helps, and I will post any other findings. Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
0 Kudos
Message 4 of 7
(4,767 Views)
Hello again,

In order to correct the issue with the numeric control getting focus on the main panel, create the numeric control and add it to the main panel before making a call to EasyTab_ConvertFromCanvas().

I have attached a modified version of Al S's code to this post. Both behaviors seem to resolved with the modification. Let me know if you see any other strange behavior.

Thanks.
Wendy L
LabWindows/CVI Developer Newsletter
Message 5 of 7
(4,760 Views)
I went ahead and looked into the root cause of this, so here it is:

EasyTabs, as a matter of course, chains the callbacks of all panels used as tabs and also of all controls on those panels (using the ChainPanelCallback and ChainCtrlCallback facilities provided in toolbox.c). This happens at the time the panel is added to the easytab control. Therefore, any control which is created on a panel that has already been added as a tab on an easytab control will not have its callback chained properly. The implication of this is that if you add controls to any tab after it has been added to an easytab control OR if you set the control callback function or callback data after adding the panel to the easytab control, the behavior is undefined. In this case, the result is that the focus event for the panel is swallowed because the control callback has not been setup as expected by the easytab control.

In short; create all controls that you want on an easytab panel before placing that panel on the easytab control. This is not well documented in the easytab documentation, but it is required.

Sorry for the trouble and confusion,

Alex
Message 6 of 7
(4,748 Views)
Thank you everyone, it helped very much.
shimonir
0 Kudos
Message 7 of 7
(4,733 Views)