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#
  4. Select next control if control is in groupbox?

Select next control if control is in groupbox?

Scheduled Pinned Locked Moved C#
question
5 Posts 4 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.
  • G Offline
    G Offline
    GrooverFromHolland
    wrote on last edited by
    #1

    Hi all, I use the following code to select the next control.

    private void opdrachtnummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
    {
    if (e.KeyChar == (char)13)
    {
    ZakdataDatabase_Insert("Opdrachtnummer", opdrachtnummerTextBox.Text);
    SelectNext_control(opdrachtnummerTextBox.Tag.ToString());

           }
       }
    

    private void SelectNext_control(string t)
    {
    bool isNextControl = false;
    int TagToFind = (int.Parse(t));
    do
    {
    TagToFind++;
    foreach (Control c in this.Controls)
    {
    if ((c.Tag != null)&&(c.Visible=true))
    {
    if (c.Tag.ToString() == TagToFind.ToString())
    {
    isNextControl = true;
    c.Select();
    }
    }
    }
    if (TagToFind > 102) break;
    } while (!isNextControl);
    }

    All controls are tagged with an incremented number. What to do if the next control is in a groupBox? Thanks, Groover.

    0200 A9 23 0202 8D 01 80 0205 00

    OriginalGriffO L B 3 Replies Last reply
    0
    • G GrooverFromHolland

      Hi all, I use the following code to select the next control.

      private void opdrachtnummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
      {
      if (e.KeyChar == (char)13)
      {
      ZakdataDatabase_Insert("Opdrachtnummer", opdrachtnummerTextBox.Text);
      SelectNext_control(opdrachtnummerTextBox.Tag.ToString());

             }
         }
      

      private void SelectNext_control(string t)
      {
      bool isNextControl = false;
      int TagToFind = (int.Parse(t));
      do
      {
      TagToFind++;
      foreach (Control c in this.Controls)
      {
      if ((c.Tag != null)&&(c.Visible=true))
      {
      if (c.Tag.ToString() == TagToFind.ToString())
      {
      isNextControl = true;
      c.Select();
      }
      }
      }
      if (TagToFind > 102) break;
      } while (!isNextControl);
      }

      All controls are tagged with an incremented number. What to do if the next control is in a groupBox? Thanks, Groover.

      0200 A9 23 0202 8D 01 80 0205 00

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      If it is in a groupbox, then you have to recursively search into each container control - which would also cover panels and so forth. But why not do it the easy way? Put the next control reference into the tag directly, instead of a number?

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      G 1 Reply Last reply
      0
      • G GrooverFromHolland

        Hi all, I use the following code to select the next control.

        private void opdrachtnummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
        if (e.KeyChar == (char)13)
        {
        ZakdataDatabase_Insert("Opdrachtnummer", opdrachtnummerTextBox.Text);
        SelectNext_control(opdrachtnummerTextBox.Tag.ToString());

               }
           }
        

        private void SelectNext_control(string t)
        {
        bool isNextControl = false;
        int TagToFind = (int.Parse(t));
        do
        {
        TagToFind++;
        foreach (Control c in this.Controls)
        {
        if ((c.Tag != null)&&(c.Visible=true))
        {
        if (c.Tag.ToString() == TagToFind.ToString())
        {
        isNextControl = true;
        c.Select();
        }
        }
        }
        if (TagToFind > 102) break;
        } while (!isNextControl);
        }

        All controls are tagged with an incremented number. What to do if the next control is in a groupBox? Thanks, Groover.

        0200 A9 23 0202 8D 01 80 0205 00

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Instead of abusing the Tag, how about adding them to a List? No matter where they'd be located, you'd always have a reference. Alternatively, use the name-property.

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          If it is in a groupbox, then you have to recursively search into each container control - which would also cover panels and so forth. But why not do it the easy way? Put the next control reference into the tag directly, instead of a number?

          Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

          G Offline
          G Offline
          GrooverFromHolland
          wrote on last edited by
          #4

          To put the next control reference into the tag directly, instead of a number cannot be done because e.g the third control can be a listbox and the Visualibility property of other controls an groupBoxes depend on the selection in the listbox or checkboxes. Can I use the TabIndex instead? Thanks, Groover.

          0200 A9 23 0202 8D 01 80 0205 00

          1 Reply Last reply
          0
          • G GrooverFromHolland

            Hi all, I use the following code to select the next control.

            private void opdrachtnummerTextBox_KeyPress(object sender, KeyPressEventArgs e)
            {
            if (e.KeyChar == (char)13)
            {
            ZakdataDatabase_Insert("Opdrachtnummer", opdrachtnummerTextBox.Text);
            SelectNext_control(opdrachtnummerTextBox.Tag.ToString());

                   }
               }
            

            private void SelectNext_control(string t)
            {
            bool isNextControl = false;
            int TagToFind = (int.Parse(t));
            do
            {
            TagToFind++;
            foreach (Control c in this.Controls)
            {
            if ((c.Tag != null)&&(c.Visible=true))
            {
            if (c.Tag.ToString() == TagToFind.ToString())
            {
            isNextControl = true;
            c.Select();
            }
            }
            }
            if (TagToFind > 102) break;
            } while (!isNextControl);
            }

            All controls are tagged with an incremented number. What to do if the next control is in a groupBox? Thanks, Groover.

            0200 A9 23 0202 8D 01 80 0205 00

            B Offline
            B Offline
            BillWoodruff
            wrote on last edited by
            #5

            I think we need some basic information here: 1. are all Controls in the GroupBox of the same Type ? If so, what Type ? If they are all the same type, why not just manipulate the TabIndex property, and let the Tab key do the work for you. 2. Have you considered the implications that a GroupBox has no 'TabStop property ? (hint: probably none !). Note that a Panel has a 'TabStop property. Run-time behavior (tabbing between Controls in a GroupBox will work as expected). 3. are Controls added at run-time to this GroupBox ? Since the last control added will have the highest TabIndex (and assuming TabStop set to 'true, and that it has a 'TabStop propery: what's the problem here. 4 issue of nested-containers as raised by OriginalGriff: if you have properly adjusted the TabIndex: I see no reason for a recursive descent here: tabbing from one Panel to another and, within the second Panel, "into a third Panel:" is no problem. So, I think to really understand if you have a unique problem here, we need to know much more about your UI structure, and the way you intend use of the Tab key to work. best, Bill

            "If you shoot at mimes, should you use a silencer ?" Stephen Wright

            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