TabStrip OnSelChanging event

Started by Jim Short, April 19, 2009, 05:21:12 PM

Previous topic - Next topic

Jim Short

To the best of my knowledge, the OnSelChanging event only fires when the user selects a new tab on the TabStrip. Also the OnChanged  event fires on form show, preselecting first tab. Placing dcl_TabStrip_SetCurSel in OnIntialize allows a different tab to show on form show. The result being OnChanged event is fired twice.

It makes sense to call OnSelChanging when a user tries to pick a new tab; forcing some action be done before the change, and perhaps permanently saving the control data somewhere else.

I was thinking that to be consistent the OnSelChanging  event should always fire if defined regardless of how the tab is changed, since dcl_TabStrip_SetCurSel accomplishes the same as picking a tab. But now I am thinking that would mean an unnecessary event call when the programmer already has control of the tab.

Comments encouraged.
Jim

Jim Short

Fred Tomke

Hello, I'm not sure if I understood you right but you can use the event SelChanging to prevent the user from changing the current tab until the right values are set.

See the API for SelChanging and the posting from Owen.

It may happen that OnChanged event is fired twice because it will fired at the point of calling Form_Show (tab will be created) and when you change the currently selected tab within OnInitialize. To avoid that code will be executed you will have to set a certain variable:

Code (autolisp) Select

(defun c:MyProg ()
  (defun c:MyProj_MyForm_OnInitialize ()
    (dcl_tab_setcursel MyProj_MyForm_TabControl intTab)
    (setq isInit nil)
  ); c:MyProj_MyForm_OnInitialize

  (defun c:MyProj_MyForm_TabControl_OnChanged (intItemIndex)
    (if (not isInit)
      (progn
        (setq intTab intItemIndex)
        (do_something)
      ); progn
    ); if
  ); c:MyProj_MyForm_TabControl_OnChanged

  (setq isInit T)
  (if (not (setq intTab (vl-registry-read strProgPath "LastTab")))
    (setq intTab 3)
  ); if
  (dcl_form_show MyProj_MyForm)
  (vl-registry-write strProgPath "LastTab" intTab)
  (princ)
); MyProg


Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

Jim Short

Fred,

The tabs on my TabStrip are hidden and being changed by SetCurSel.

OnSelChanging only works if a tab is picked by the user. I was thinking that this event should fire because the tab was about to change regardless of how the tab was caused to change.

Jim
Jim Short

mtiongson45

Quote from: Fred Tomke on April 20, 2009, 07:07:11 AM

  (setq isInit T)
  (if (not (setq intTab (vl-registry-read strProgPath "LastTab")))
    (setq intTab 3)
  ); if
  (dcl_form_show MyProj_MyForm)
  (vl-registry-write strProgPath "LastTab" intTab)
  (princ)


I know this is a really old topic, but could someone explain to me what the "3" represents on the line (setq intTab 3)? I've been working on a dialog box with tabs. Thanks in advance.

roy_043

The 3 is the index of the fourth tab in the tab strip. If no index is stored in the registry Fred's example uses this index as the default.

mtiongson45

Thanks for the reply. That's what I thought, but figured asking couldn't hurt.