How to Get Value from Selected Item in Listview
Tuesday, April 21, 2009 - 12:06
I am struggling before on how to get value from selected item in a listview.
As you've seen in my Hotel Reservation System (VB.NET Version) I use the following code to get the value from a Listview.
Dim FolioNumber As String For Each sItem As ListViewItem In lvList.SelectedItems FolioNumber = sItem.Text Next
Although it is working fine but the succeding code will generate an error in the IDE of VB.NET.
With frmCheckIn .State = modGlobal.FormState.adStatePopupMode .FolioNumber = FolioNumber '< = Variable "FolioNumber" is used before it has been assigned a value. A null reference exception could result at runtime. .ShowDialog() Call FillList() End With
After searching the internet I found a good solution to this problem. Just change the code above with this code:
.FolioNumber = lvList.SelectedItems(0).Text

Add new comment