Question need to display the selected item frm a list box in to a label.

ramesh017

New member
Joined
Aug 5, 2009
Messages
3
Programming Experience
Beginner
Hi

I have items in a listbox. the user have to select one item(its mandatory) and after have to click next button to proceed to the next form. in the second form the selected item should be displayed in a label.

Any help would be appreciated.
 
Try this
VB.NET:
Public Class Form1

    Public ReadOnly Property ListBoxItem() As String
        Get
            Return ListBox1.Text
        End Get

    End Property
    
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim frm2 As New Form2
        frm2.Show()
    End Sub
End Class

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Label1.Text = Form1.ListBoxItem
    End Sub
End Class
 
Thanks ofr your help!!!

but while next time selecting another item in the list box.. its not take effect in the label..its showing the previous selction...
 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If ListBox1.SelectedIndex <> -1 Then

Frm2.Show()

Frm2.Label1.Text = ListBox1.SelectedItem
Else
MessageBox.Show("select item")

End If


End Sub


hope this helps
 
Back
Top