Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to implement Tab order to the controls in a MFC Dialog box

How to implement Tab order to the controls in a MFC Dialog box

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++tutorial
15 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kapardhi
    wrote on last edited by
    #1

    Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!

    N A N 3 Replies Last reply
    0
    • K kapardhi

      Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      open your dialog in the IDE, Press "Ctrl + D". This will display the current tab order. Click on each controls in the order in which you want to set tab-order.

      nave [OpenedFileFinder] [My Blog]

      N 1 Reply Last reply
      0
      • K kapardhi

        Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!

        A Offline
        A Offline
        ATM CodeProject
        wrote on last edited by
        #3

        Hi, LayoutMenu->TabOrder

        1 Reply Last reply
        0
        • K kapardhi

          Hai! In my application there is a dialog containing various controls like 3 buttons, 2 Radio buttons etc. How can i specify a Tab order for them i.e when i first press Tab on keyboard the 1st button in my dialog must be highlighted, when i again press "Tab" on keyboard 2nd button must be highlighted, How to implement this and how to specify the order? Thanks!

          N Offline
          N Offline
          Nishad S
          wrote on last edited by
          #4

          If you are using resource editor, you can set the tab order there. It is available in "Layout" menu in VC6 and "Format" menu VC9. Shortcut key is Ctrl + D (in VC6 keyboard shortcut map). Then you can see the tab order indication for all controls. You can click on each controls to sequence. If you are creating the controls dynamically, the creation order sets the tab order. You can change it by using SetWindowPos().

          - ns ami -

          A 1 Reply Last reply
          0
          • N Nishad S

            If you are using resource editor, you can set the tab order there. It is available in "Layout" menu in VC6 and "Format" menu VC9. Shortcut key is Ctrl + D (in VC6 keyboard shortcut map). Then you can see the tab order indication for all controls. You can click on each controls to sequence. If you are creating the controls dynamically, the creation order sets the tab order. You can change it by using SetWindowPos().

            - ns ami -

            A Offline
            A Offline
            AJ83
            wrote on last edited by
            #5

            Hi ns Ami, I am creating dynamic edit box in Group Box. My current Tab order is Group Box, OK, Cancel button. Now I want tab order as: Group box-> Edit Box 1 -> Edit Box 2 -> Edit Box 3 -> OK -> Cancel. How can i achieve this? do you have any idea? Regards, Anshul

            N 1 Reply Last reply
            0
            • A AJ83

              Hi ns Ami, I am creating dynamic edit box in Group Box. My current Tab order is Group Box, OK, Cancel button. Now I want tab order as: Group box-> Edit Box 1 -> Edit Box 2 -> Edit Box 3 -> OK -> Cancel. How can i achieve this? do you have any idea? Regards, Anshul

              N Offline
              N Offline
              Nishad S
              wrote on last edited by
              #6

              I presume that "dynamic edit box" means you are creating edit box dynamically at run time. If so, you can use SetWindowPos API to set the Z-order of edit control. You will get more information from the API documentation. The parameter hWndInsertAfter (or pWndInsertAfter in the case of MFC) can be the window handle of control, which is needed to be before in tab order. For example, m_edit2.SetWindowPos( &m_edit1, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZER | SWP_NOACTIVATE ); This will set the tab order as edit1 -> edit2. Hope this info will help.

              - ns ami -

              A 1 Reply Last reply
              0
              • N Nishad S

                I presume that "dynamic edit box" means you are creating edit box dynamically at run time. If so, you can use SetWindowPos API to set the Z-order of edit control. You will get more information from the API documentation. The parameter hWndInsertAfter (or pWndInsertAfter in the case of MFC) can be the window handle of control, which is needed to be before in tab order. For example, m_edit2.SetWindowPos( &m_edit1, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZER | SWP_NOACTIVATE ); This will set the tab order as edit1 -> edit2. Hope this info will help.

                - ns ami -

                A Offline
                A Offline
                AJ83
                wrote on last edited by
                #7

                Hi Ami, I am creating edit box in Group box as:

                #define ID_CURRENT_SN_EDIT 2000

                m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
                int pointY = 0;
                int i = 0;

                for (int x = 0; x < m_vecpData->size(); x++, i++)
                {
                pointY = 30 + (i * 35);
                m_ceEdit = new CEdit;
                m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY | WS_TABSTOP, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
                m_ceEdit->SetWindowText(m_vecpData->at(x).c_str());
                m_ceEdit->SetWindowPos(m_gbGroupBox, HWND_BOTTOM , 10, pointY, 130, pointY + 25, SWP_NOSIZE); // This line is not working.:confused:
                m_ceEdit->ShowWindow(SW_SHOWNORMAL);
                }

                N 1 Reply Last reply
                0
                • A AJ83

                  Hi Ami, I am creating edit box in Group box as:

                  #define ID_CURRENT_SN_EDIT 2000

                  m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
                  int pointY = 0;
                  int i = 0;

                  for (int x = 0; x < m_vecpData->size(); x++, i++)
                  {
                  pointY = 30 + (i * 35);
                  m_ceEdit = new CEdit;
                  m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY | WS_TABSTOP, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
                  m_ceEdit->SetWindowText(m_vecpData->at(x).c_str());
                  m_ceEdit->SetWindowPos(m_gbGroupBox, HWND_BOTTOM , 10, pointY, 130, pointY + 25, SWP_NOSIZE); // This line is not working.:confused:
                  m_ceEdit->ShowWindow(SW_SHOWNORMAL);
                  }

                  N Offline
                  N Offline
                  Nishad S
                  wrote on last edited by
                  #8

                  In this case the tab order will be same as the creation order. So no need to set the Z-order again. Anyway, is this a compilable code? Argument count of SetWindowPos seems as wrong. Note that you are creating edit control as child of that GroupBox (a static control, i think). In that case the tab key navigation will not enter to the controls inside the GroupBox. Applying WS_EX_CONTROLPARENT style to GroupBox will help you. For instance, m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT );

                  - ns ami -

                  A 1 Reply Last reply
                  0
                  • N Nishad S

                    In this case the tab order will be same as the creation order. So no need to set the Z-order again. Anyway, is this a compilable code? Argument count of SetWindowPos seems as wrong. Note that you are creating edit control as child of that GroupBox (a static control, i think). In that case the tab key navigation will not enter to the controls inside the GroupBox. Applying WS_EX_CONTROLPARENT style to GroupBox will help you. For instance, m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT );

                    - ns ami -

                    A Offline
                    A Offline
                    AJ83
                    wrote on last edited by
                    #9

                    This is my modified compilable code but tab order is not working as GRPBox -> Edit 1 -> Edit 2 -> Edit 3 -> OK -> CANCEL. It is still working as **GRPBox -> OK -> CANCEL.**

                    #define ID_CURRENT_SN_EDIT 1003

                    m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
                    m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT);

                    m_btnOK = (CButton*)GetDlgItem(IDC_OK);
                    m_btnCancel = (CButton*)GetDlgItem(IDC_CANCEL);

                    int pointY = 0;
                    int i = 0;

                    for (int x = 0; x < m_vecpData->size(); x++, i++)
                    {
                    pointY = 30 + (i * 35);
                    m_ceEdit = new CEdit;
                    m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
                    m_ceEdit>SetWindowText(m_vecpData->at(x).c_str());
                    int nCtlrID = ID_CURRENT_SN_EDIT + i;

                    if (x > 0)
                    {
                    CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1);
                    m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
                    }
                    m_ceEdit->ShowWindow(SW_SHOWNORMAL);
                    }

                    Any Help or Suggestion!! I do not know what to do now.

                    N 1 Reply Last reply
                    0
                    • A AJ83

                      This is my modified compilable code but tab order is not working as GRPBox -> Edit 1 -> Edit 2 -> Edit 3 -> OK -> CANCEL. It is still working as **GRPBox -> OK -> CANCEL.**

                      #define ID_CURRENT_SN_EDIT 1003

                      m_gbGroupBox = (CStatic*)GetDlgItem(IDC_GROUPBOX);
                      m_gbGroupBox->ModifyStyleEx( 0, WS_EX_CONTROLPARENT);

                      m_btnOK = (CButton*)GetDlgItem(IDC_OK);
                      m_btnCancel = (CButton*)GetDlgItem(IDC_CANCEL);

                      int pointY = 0;
                      int i = 0;

                      for (int x = 0; x < m_vecpData->size(); x++, i++)
                      {
                      pointY = 30 + (i * 35);
                      m_ceEdit = new CEdit;
                      m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);
                      m_ceEdit>SetWindowText(m_vecpData->at(x).c_str());
                      int nCtlrID = ID_CURRENT_SN_EDIT + i;

                      if (x > 0)
                      {
                      CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1);
                      m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE );
                      }
                      m_ceEdit->ShowWindow(SW_SHOWNORMAL);
                      }

                      Any Help or Suggestion!! I do not know what to do now.

                      N Offline
                      N Offline
                      Nishad S
                      wrote on last edited by
                      #10

                      :) Well, you missed WS_TABSTOP style.

                      AJ83 wrote:

                      m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);

                      And the following is not needed...

                      AJ83 wrote:

                      if (x > 0) { CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1); m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE ); } m_ceEdit->ShowWindow(SW_SHOWNORMAL);

                      - ns ami -

                      A 1 Reply Last reply
                      0
                      • N Nishad S

                        :) Well, you missed WS_TABSTOP style.

                        AJ83 wrote:

                        m_ceEdit->Create(WS_VISIBLE| WS_BORDER |ES_READONLY, CRect(10, pointY, 130, pointY + 25), m_gbGroupBox, ID_CURRENT_SN_EDIT + i);

                        And the following is not needed...

                        AJ83 wrote:

                        if (x > 0) { CEdit* pEdit = (CEdit*)GetDlgItem(nCtlrID - 1); m_ceEdit->SetWindowPos(pEdit, 10, pointY, 130, pointY + 25, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE ); } m_ceEdit->ShowWindow(SW_SHOWNORMAL);

                        - ns ami -

                        A Offline
                        A Offline
                        AJ83
                        wrote on last edited by
                        #11

                        Hey Ami, **Thanks a lot for your valuable suggestion. It is working now. great :) !!!** Now my another task is: There is one Static GRPbox which has been created in CFormView by using ToolBox. Now in Static Groupbox, I am creating "n" number of dynamic GrpBox. In Dynamic GrpBox, I am creating dynamic Edit Box (few are READ ONLY too). Now I have to set taborder for that also. Any suggestion on this.? Regards, Anshul

                        N 1 Reply Last reply
                        0
                        • A AJ83

                          Hey Ami, **Thanks a lot for your valuable suggestion. It is working now. great :) !!!** Now my another task is: There is one Static GRPbox which has been created in CFormView by using ToolBox. Now in Static Groupbox, I am creating "n" number of dynamic GrpBox. In Dynamic GrpBox, I am creating dynamic Edit Box (few are READ ONLY too). Now I have to set taborder for that also. Any suggestion on this.? Regards, Anshul

                          N Offline
                          N Offline
                          Nishad S
                          wrote on last edited by
                          #12

                          I believe that, since you could understand your first solution well, you can implement this easily. :) Or, are you in any trouble with that?

                          - ns ami -

                          A 1 Reply Last reply
                          0
                          • N Nishad S

                            I believe that, since you could understand your first solution well, you can implement this easily. :) Or, are you in any trouble with that?

                            - ns ami -

                            A Offline
                            A Offline
                            AJ83
                            wrote on last edited by
                            #13

                            Well, In first round it is working but once it comes to OK or CANCEL button is not going back to edit box. I am trying for that... I will post code after few minutes or if you do have idea of why is it not coming back to edit box, you can let me know.. Regards, Anshul

                            A 1 Reply Last reply
                            0
                            • A AJ83

                              Well, In first round it is working but once it comes to OK or CANCEL button is not going back to edit box. I am trying for that... I will post code after few minutes or if you do have idea of why is it not coming back to edit box, you can let me know.. Regards, Anshul

                              A Offline
                              A Offline
                              AJ83
                              wrote on last edited by
                              #14

                              Hi Ami, My problem has been resolved. your given suggestion worked out. **Thanks a lot once again..... :)**

                              1 Reply Last reply
                              0
                              • N Naveen

                                open your dialog in the IDE, Press "Ctrl + D". This will display the current tab order. Click on each controls in the order in which you want to set tab-order.

                                nave [OpenedFileFinder] [My Blog]

                                N Offline
                                N Offline
                                Nahida HK
                                wrote on last edited by
                                #15

                                I did That But the tab order doesn't work on checkbox and RadioButton and i don't know why !!

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups