• We just launched and are currently in beta. Join us as we build and grow the community.

How to Get Value from Selected Item in Listview

shakira

Container Orchestrator
S Rep
0
0
0
Rep
0
S Vouches
0
0
0
Vouches
0
Posts
174
Likes
77
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
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. .

    ShowDialog

    (

    )

  5. Call

    FillList(

    )
  6. 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

 

452,292

323,348

323,357

Top