How to Get Value from Selected Item in Listview

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.
  1. Dim FolioNumber As String
  2. For Each sItem As ListViewItem In lvList.SelectedItems
  3.      FolioNumber = sItem.Text
  4. Next
Although it is working fine but the succeding code will generate an error in the IDE of VB.NET.
  1.         With frmCheckIn
  2.             .State = modGlobal.FormState.adStatePopupMode
  3.             .FolioNumber = FolioNumber '< = Variable "FolioNumber" is used before it has been assigned a value. A null reference exception could result at runtime.
  4.  
  5.             .ShowDialog()
  6.  
  7.             Call FillList()
  8.         End With
After searching the internet I found a good solution to this problem. Just change the code above with this code:
  1. .FolioNumber = lvList.SelectedItems(0).Text

Add new comment