jsctechy
asked on
ListBox, how to get the item pick and do something with it
hi,
How can i show in a message box the item selected on a listBox?
here is the code i'm using:
Private Sub frmTableMaintenance_Shown( ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Dim dt As DataTable = com.library.data.Tools.Get TableAcces s()
Dim dtrw As DataRow
dtrw = dt.Rows(0)
For Each dtrw In dt.Rows
strFormName.Items.Add(dtrw ("strTable Name"))
Next
MsgBox("You have Selected: " & strFormName.SelectedItem)
End Sub
How can i show in a message box the item selected on a listBox?
here is the code i'm using:
Private Sub frmTableMaintenance_Shown(
Dim dt As DataTable = com.library.data.Tools.Get
Dim dtrw As DataRow
dtrw = dt.Rows(0)
For Each dtrw In dt.Rows
strFormName.Items.Add(dtrw
Next
MsgBox("You have Selected: " & strFormName.SelectedItem)
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you really need to do that you can do it this way:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As Form = CType(System.Reflection.As sembly.Get ExecutingA ssembly.Cr eateInstan ce("Window sApplicati on1.Form2" ), Form)
frm.ShowDialog()
End Sub
Because it is declared as Form and not as Form2, you will not be able to access any custom properties or methods of Form2.
With a little more code, you can have strongly typed forms:
Select Case FormName
Case "Form2"
Dim frm As Form2
If frm.ShowDialog = Windows.Forms.DialogResult .OK Then
'use custom methods of Form2...
End If
Case "Form3"
'...
End Select
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm As Form = CType(System.Reflection.As
frm.ShowDialog()
End Sub
Because it is declared as Form and not as Form2, you will not be able to access any custom properties or methods of Form2.
With a little more code, you can have strongly typed forms:
Select Case FormName
Case "Form2"
Dim frm As Form2
If frm.ShowDialog = Windows.Forms.DialogResult
'use custom methods of Form2...
End If
Case "Form3"
'...
End Select
ASKER
for nstance lets said my first value is frmTax then once i double click on it the message box will display but instead of doing this i want to display the form that has the same name?