Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract selections from a listbox 1

Status
Not open for further replies.

Malchik

Programmer
Dec 8, 2001
148
CA
Hi,

I am trying to extract the selected information from a listbox and I can't get what I want. For a test, I tried this:

For iCount = 0 To lstEmail.Items.Count - 1
If lstTest.GetSelected(iCount) = True Then
MsgBox(lstTest.SelectedItem.ToString)
End If
Next

I select one record and press a button. the code is called. The MSGBOX returns System.Data.DataRowView, instead of the selected item, which is ABC. I do not know if it matters, but this listbox is loaded with a DataMember from an Access database.

Thanks for your help. In VB that was easy, but I cannot figure that out in .NET :(

Thanks for your help.

Mal'chik [bigglasses]
 
Try this:

Code:
		For a As Integer = 0 To ListBox1.Items.Count - 1
			If ListBox1.GetSelected(a) Then
				MessageBox.Show(ListBox1.Items(a).ToString)
			End If
		Next


Hope this helps.

[vampire][bat]
 
Thanks Earthandfire it is working if the the listbox is not linked to a DB, but if it is linked to a DB i got System.Data.DataRowView... I am continuing to search...

Mal'chik [bigglasses]
 
You need to specify the column of the data you want returned.

i.e:

Code:
Dim tmpRowView = CType(ListBox1.Items(0), DataRowView).Item(<fieldindex>).ToString

Where <fieldindex> is the column of your db table you want to display.
 
Thans Qamgine.... it works wonder! It would have take me a long time to figure that one out... here's a star

Mal'chik [bigglasses]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top