none
Using a TextBox inside a GroupBox

    Question

  • Hello,

    please could you help me with coding.
    I have two GroupBox (players, game)
    Inside first box(players) I have two TextBoxs (name, surname)x(24rows) and in second (game) only one Label for each player.

    I need join name and surname from first GroupBox to Label in second GroupBox after press button inside first GroupBox.

    I use GroupBox for easy hidden (property visible) all TextBoxes at once.

    Sorry for my English.

    Thanks Namrmic

    Sunday, January 13, 2013 2:24 AM

Answers

  • You can do that in a For Index, however be aware it will cost your not much less code than writing those 24 lines and it is much more confusing. 

    It will be something like

            Dim GroupBox1TextBoxes() As Control = {TextBox1, TexBox2, Textbox3}
            Dim Groupbox2TextBoxes() As Control = {TextBoxA, TexBoxB, TextboxC}
            Dim Groupbox2Labels() As Control = {Labely, Labelx, Labelz}
            For i = 0 To GroupBox1TextBoxes.Length - 1
                Groupbox2Labels(i).Text = GroupBox1TextBoxes(i).Text & " " & Groupbox2TextBoxes(i).Text
            Next


    Success
    Cor


    Sunday, January 13, 2013 4:43 PM
  • try this:

    Label1.Text = Textbox1.Text & Textbox2.Text & Label1.Text

    Label2.Text = Textbox3.Text & Textbox4.Text & Label2.Text

    .

    .

    Label24.Text = Textbox47.Text & Textbox48.Text & Label24.Text

    Sunday, January 13, 2013 3:05 AM
  • Namrmic

    I assume it is windows forms. In that the Groupbox is not important for programming, you can just use the name of the textobxes

    TheLabel = TextBoxFirstName.Text & " " & TextboxLastName.Text


    Success
    Cor

    Sunday, January 13, 2013 11:09 AM
  • Hello namrmic,

    another example with the use of liqtoobjects and of the collection, the whole then saved in a third collection that groups the data of the first two and displays them on the screen.

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim myValueTextBox As List(Of String) = (From textbox In GroupBox1.Controls.OfType(Of TextBox)() Select textbox.Text).ToList()
            Dim myValueLabel As List(Of String) = (From label In GroupBox2.Controls.OfType(Of Label)() Select label.Text).ToList()
            Dim value As New List(Of String)
    
            For i As Integer = 0 To myValueTextBox.Count - 1
                value.Add(String.Concat(myValueTextBox(i), myValueLabel(i)))
            Next
    
            For index As Integer = 0 To value.Count - 1
                MessageBox.Show(value(index).ToString())
            Next
        End Sub

    Regards.


    • Marked as answer by namrmic Monday, January 14, 2013 12:29 AM
    Sunday, January 13, 2013 5:41 PM

All replies

  • try this:

    Label1.Text = Textbox1.Text & Textbox2.Text & Label1.Text

    Label2.Text = Textbox3.Text & Textbox4.Text & Label2.Text

    .

    .

    Label24.Text = Textbox47.Text & Textbox48.Text & Label24.Text

    Sunday, January 13, 2013 3:05 AM
  • Namrmic

    I assume it is windows forms. In that the Groupbox is not important for programming, you can just use the name of the textobxes

    TheLabel = TextBoxFirstName.Text & " " & TextboxLastName.Text


    Success
    Cor

    Sunday, January 13, 2013 11:09 AM
  • Yes, I now about this but can I use For...Next, Do...Loop or any other function?

    Thanks

    Sunday, January 13, 2013 1:21 PM
  • You can do that in a For Index, however be aware it will cost your not much less code than writing those 24 lines and it is much more confusing. 

    It will be something like

            Dim GroupBox1TextBoxes() As Control = {TextBox1, TexBox2, Textbox3}
            Dim Groupbox2TextBoxes() As Control = {TextBoxA, TexBoxB, TextboxC}
            Dim Groupbox2Labels() As Control = {Labely, Labelx, Labelz}
            For i = 0 To GroupBox1TextBoxes.Length - 1
                Groupbox2Labels(i).Text = GroupBox1TextBoxes(i).Text & " " & Groupbox2TextBoxes(i).Text
            Next


    Success
    Cor


    Sunday, January 13, 2013 4:43 PM
  • Hello namrmic,

    another example with the use of liqtoobjects and of the collection, the whole then saved in a third collection that groups the data of the first two and displays them on the screen.

     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim myValueTextBox As List(Of String) = (From textbox In GroupBox1.Controls.OfType(Of TextBox)() Select textbox.Text).ToList()
            Dim myValueLabel As List(Of String) = (From label In GroupBox2.Controls.OfType(Of Label)() Select label.Text).ToList()
            Dim value As New List(Of String)
    
            For i As Integer = 0 To myValueTextBox.Count - 1
                value.Add(String.Concat(myValueTextBox(i), myValueLabel(i)))
            Next
    
            For index As Integer = 0 To value.Count - 1
                MessageBox.Show(value(index).ToString())
            Next
        End Sub

    Regards.


    • Marked as answer by namrmic Monday, January 14, 2013 12:29 AM
    Sunday, January 13, 2013 5:41 PM