locked
Multiple Textboxes to Listbox

    Question

  • I've been looking all over for some help to code about five textboxes into a listbox and only showing the name of one of the textboxes in the listbox. Also how do i get the listbox file to open back into the five textboxes?

    Thanks
    Sunday, October 28, 2007 2:16 AM

Answers

  •         private void button2_Click(object sender, EventArgs e)
            {
                //change textbox text to the listbox
                listBox1.Items.Clear(); //maybe clear the listbox before addiing new values
                listBox1.Items.Add(textBox1.Text);
                listBox1.Items.Add(textBox2.Text);
                listBox1.Items.Add(textBox3.Text);
                listBox1.Items.Add(textBox4.Text);
                listBox1.Items.Add(textBox5.Text);
            }

            private void button3_Click(object sender, EventArgs e)
            {
                //from the listbox to the textboxes
                textBox1.Text = listBox1.Items[0].ToString();
                textBox2.Text = listBox1.Items[1].ToString();
                textBox3.Text = listBox1.Items[2].ToString();
                textBox4.Text = listBox1.Items[3].ToString();
                textBox5.Text = listBox1.Items[4].ToString();
            }
    Sunday, October 28, 2007 12:52 PM
  • If that is what you are trying to do, here is the Visual Basic (cameron....this is VB Smile )

    Code Block

     

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    'change textbox text to the listbox

    ListBox1.Items.Clear() 'maybe clear the listbox before addiing new values

    ListBox1.Items.Add(TextBox1.Text)

    ListBox1.Items.Add(TextBox2.Text)

    ListBox1.Items.Add(TextBox3.Text)

    ListBox1.Items.Add(TextBox4.Text)

    ListBox1.Items.Add(TextBox5.Text)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    'from the listbox to the textboxes

    TextBox1.Text = ListBox1.Items.Item(0).ToString()

    TextBox1.Text = ListBox1.Items.Item(1).ToString()

    TextBox1.Text = ListBox1.Items.Item(2).ToString()

    TextBox1.Text = ListBox1.Items.Item(3).ToString()

    TextBox1.Text = ListBox1.Items.Item(4).ToString()

    End Sub

     

     

    Thanks,

    paoloTheCool

    Sunday, October 28, 2007 1:06 PM

All replies

  • Can you explain a little more what you are trying to do?

     

    Thanks,

    paoloTheCool

     

    Sunday, October 28, 2007 3:25 AM
  •         private void button2_Click(object sender, EventArgs e)
            {
                //change textbox text to the listbox
                listBox1.Items.Clear(); //maybe clear the listbox before addiing new values
                listBox1.Items.Add(textBox1.Text);
                listBox1.Items.Add(textBox2.Text);
                listBox1.Items.Add(textBox3.Text);
                listBox1.Items.Add(textBox4.Text);
                listBox1.Items.Add(textBox5.Text);
            }

            private void button3_Click(object sender, EventArgs e)
            {
                //from the listbox to the textboxes
                textBox1.Text = listBox1.Items[0].ToString();
                textBox2.Text = listBox1.Items[1].ToString();
                textBox3.Text = listBox1.Items[2].ToString();
                textBox4.Text = listBox1.Items[3].ToString();
                textBox5.Text = listBox1.Items[4].ToString();
            }
    Sunday, October 28, 2007 12:52 PM
  • If that is what you are trying to do, here is the Visual Basic (cameron....this is VB Smile )

    Code Block

     

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

    'change textbox text to the listbox

    ListBox1.Items.Clear() 'maybe clear the listbox before addiing new values

    ListBox1.Items.Add(TextBox1.Text)

    ListBox1.Items.Add(TextBox2.Text)

    ListBox1.Items.Add(TextBox3.Text)

    ListBox1.Items.Add(TextBox4.Text)

    ListBox1.Items.Add(TextBox5.Text)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    'from the listbox to the textboxes

    TextBox1.Text = ListBox1.Items.Item(0).ToString()

    TextBox1.Text = ListBox1.Items.Item(1).ToString()

    TextBox1.Text = ListBox1.Items.Item(2).ToString()

    TextBox1.Text = ListBox1.Items.Item(3).ToString()

    TextBox1.Text = ListBox1.Items.Item(4).ToString()

    End Sub

     

     

    Thanks,

    paoloTheCool

    Sunday, October 28, 2007 1:06 PM
  • oh, woops Wink
    Sunday, October 28, 2007 1:08 PM
  • Basically what i'm trying to do is:
    -have the 5 textboxes add data to the listbox
    -have the data inserted appear in one line with only one of the values in say textbox 1
    ex.  test00  in textbox 1
          test23  in textbox 2
                    test12  in textbox 3
          test15  in textbox 4
          test30  in textbox 5
    send data to listbox
    have only the test00 from textbox 1 appear in the listbox

    -have the listbox insert the data back into the 5 textboxes

    Thanks again
    Tuesday, October 30, 2007 12:17 AM