Hello,

Please tell me how to add a string item to a text box, returned from another form that has a list box?

I have two forms.

on the first form I have a button which calls another form that has a List Box.
When I select the value from the list box and click on the apply button then the value should be passed to the first form that will also have a text box.

The text box should contain the value of list box.

Please help me in this.

Recommended Answers

All 3 Replies

public class form1
'Put textbox and button1 on form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Visible = True
    End Sub
End class


Public Class Form2
'put listbox1,button1 on form 2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.Add("TEST")
        ListBox1.Items.Add("TEST1")
        ListBox1.Items.Add("TEST2")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Form1.TextBox1.Text = ListBox1.SelectedItem
        Me.Visible = False
        Form1.Visible = True

    End Sub
End Class
public class form1
'Put textbox and button1 on form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Form2.Visible = True
    End Sub
End class


Public Class Form2
'put listbox1,button1 on form 2
    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ListBox1.Items.Add("TEST")
        ListBox1.Items.Add("TEST1")
        ListBox1.Items.Add("TEST2")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Form1.TextBox1.Text = ListBox1.SelectedItem
        Me.Visible = False
        Form1.Visible = True

    End Sub
End Class

this has helped me a lot....
Thank u so much

but can u tell me that without again opening the form1 how can the value be set

Do

form1.visible = false
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.