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 access all the Editboxes in a form.

How to access all the Editboxes in a form.

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
12 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.
  • A Anand Todkar

    I have more than 50 Edit boexs in a form and I want to access them in a loop rather than accessing one by one, Is there any way by which I can do it?

    Thanks, Anand.

    H Offline
    H Offline
    Hamid Taebi
    wrote on last edited by
    #2

    Each editbox has an ID if you set these ids for example of 100 to 150 on the resource.h you can use of a loop.

    A C 2 Replies Last reply
    0
    • H Hamid Taebi

      Each editbox has an ID if you set these ids for example of 100 to 150 on the resource.h you can use of a loop.

      A Offline
      A Offline
      Anand Todkar
      wrote on last edited by
      #3

      Yeah right, but the project has more than 50 forms and i have to do this for all forms, already the resource IDs are tightly bound ... more , it is not reliable to .. So i was thinking if some generic loop by which we can access all the controls on form and then screen out the other controls.

      Thanks, Anand.

      N D 2 Replies Last reply
      0
      • A Anand Todkar

        I have more than 50 Edit boexs in a form and I want to access them in a loop rather than accessing one by one, Is there any way by which I can do it?

        Thanks, Anand.

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

        Anand Todkar wrote:

        Is there any way by which I can do it?

        Set the taborder of all EditBox in a sequence. Now take the handle of EditBox in the top of zorder and call the GetWindow() with GW_HWNDNEXT. This will return the handle to the 2nd EditBox. now pass the 2nd EditBox handle to get third list and so on. Another option is to set the id value of the EditBox in a sequence. Now call the GetDlgItem() function in a for loop with the index starting from the id of first EditBox to the last one.

        nave [OpenedFileFinder]

        A 1 Reply Last reply
        0
        • H Hamid Taebi

          Each editbox has an ID if you set these ids for example of 100 to 150 on the resource.h you can use of a loop.

          C Offline
          C Offline
          CodingLover
          wrote on last edited by
          #5

          You mean something like that, #define IDC_ONE 1000 #define IDC_TWO 1001 So, there can I use any number. I mean there is no restrictions on predefined events?

          I appreciate your help all the time... Eranga:)

          H 1 Reply Last reply
          0
          • A Anand Todkar

            Yeah right, but the project has more than 50 forms and i have to do this for all forms, already the resource IDs are tightly bound ... more , it is not reliable to .. So i was thinking if some generic loop by which we can access all the controls on form and then screen out the other controls.

            Thanks, Anand.

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

            Anand Todkar wrote:

            Yeah right, but the project has more than 50 forms

            Do all the forms have a common main dialog?

            nave [OpenedFileFinder]

            1 Reply Last reply
            0
            • N Naveen

              Anand Todkar wrote:

              Is there any way by which I can do it?

              Set the taborder of all EditBox in a sequence. Now take the handle of EditBox in the top of zorder and call the GetWindow() with GW_HWNDNEXT. This will return the handle to the 2nd EditBox. now pass the 2nd EditBox handle to get third list and so on. Another option is to set the id value of the EditBox in a sequence. Now call the GetDlgItem() function in a for loop with the index starting from the id of first EditBox to the last one.

              nave [OpenedFileFinder]

              A Offline
              A Offline
              Anand Todkar
              wrote on last edited by
              #7

              Naveen.R wrote:

              Set the taborder of all EditBox in a sequence. Now take the handle of EditBox in the top of zorder and call the GetWindow() with GW_HWNDNEXT. This will return the handle to the 2nd EditBox. now pass the 2nd EditBox handle to get third list and so on.

              This sounds good, let me try this way, as the Taborder is not going to change. Thanks naveen :)

              Thanks, Anand.

              1 Reply Last reply
              0
              • C CodingLover

                You mean something like that, #define IDC_ONE 1000 #define IDC_TWO 1001 So, there can I use any number. I mean there is no restrictions on predefined events?

                I appreciate your help all the time... Eranga:)

                H Offline
                H Offline
                Hamid Taebi
                wrote on last edited by
                #8

                Not any number,numbers must unique.

                C 1 Reply Last reply
                0
                • H Hamid Taebi

                  Not any number,numbers must unique.

                  C Offline
                  C Offline
                  CodingLover
                  wrote on last edited by
                  #9

                  Ya, its' true. What I mean that there is any numbers couldn't I use, may be those numbers are already use somewhere in the application.

                  I appreciate your help all the time... Eranga:)

                  1 Reply Last reply
                  0
                  • A Anand Todkar

                    I have more than 50 Edit boexs in a form and I want to access them in a loop rather than accessing one by one, Is there any way by which I can do it?

                    Thanks, Anand.

                    N Offline
                    N Offline
                    Nelek
                    wrote on last edited by
                    #10

                    Hi, I made it very easy with an Array from pointers to the control. In my case, it was:

                    CMyColorComboBox* m_aComboBoxes [MAX];

                    then, in the constructor of the Dialog... I wrote the access to them. m_aComboBoxes[0] = &m_cmcbbVisIn1; m_aComboBoxes[1] = &m_cmcbbVisIn2; m_aComboBoxes[2] = &m_cmcbbVisIn3; m_aComboBoxes[3] = &m_cmcbbVisIn4; and then I use loops to access, write, delete data from them.

                    for (int i = 0; i < MAX; i++)
                    m_aComboBoxes [MAX]->ResetContent ();

                    I have done it in that way because I had the member variables from class wizard. But you can use the idea as well without having any variable and using GetDlgItem (ID). If you use the GetDlgItem ... then you must use OnInitDialog or on InitialUpdate. Because if you use the constructor to give the pointers... then you will have an assertion because the window doesn't exist when trying to access. Hope it helps

                    Greetings. -------- M.D.V. If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you ;)

                    1 Reply Last reply
                    0
                    • A Anand Todkar

                      Yeah right, but the project has more than 50 forms and i have to do this for all forms, already the resource IDs are tightly bound ... more , it is not reliable to .. So i was thinking if some generic loop by which we can access all the controls on form and then screen out the other controls.

                      Thanks, Anand.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #11

                      Anand Todkar wrote:

                      ...already the resource IDs are tightly bound ... more , it is not reliable to...

                      What exactly do you mean by this? Why can't you just open the project's resource.h file (or whatever you have named it) and renumber the controls such that they are sequential?


                      "A good athlete is the result of a good and worthy opponent." - David Crow

                      "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                      A 1 Reply Last reply
                      0
                      • D David Crow

                        Anand Todkar wrote:

                        ...already the resource IDs are tightly bound ... more , it is not reliable to...

                        What exactly do you mean by this? Why can't you just open the project's resource.h file (or whatever you have named it) and renumber the controls such that they are sequential?


                        "A good athlete is the result of a good and worthy opponent." - David Crow

                        "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                        A Offline
                        A Offline
                        Anand Todkar
                        wrote on last edited by
                        #12

                        Yeah David, you are right, i done the changes in Resource file and accessed the Controls in a loop. Thanks for your help.

                        Thanks, Anand.

                        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