Skip to main content

How to Get the Selected Value from Listview


Getting a value from a ListView is one of the most common questions I found on the Internet.

So, to help you find the value of a SelectedItem in your Listview, let’s take some example.

Supposed you have a Listview with the following column:

  1. With lvList
  2. .Clear()
  3.  
  4. .View = View.Details
  5. .FullRowSelect = True
  6. .GridLines = True
  7. .Columns.Add("ProductDetailID", 0)
  8. .Columns.Add("Category", 100)
  9. .Columns.Add("Brand", 100)
  10. .Columns.Add("Description", 250)
  11. .Columns.Add("U/M", 100)
  12. .Columns.Add("Qty On Hand", 100, HorizontalAlignment.Right)
  13. .Columns.Add("Selling Price", 100, HorizontalAlignment.Right)
  14.  
  15. FillListView(lvList, GetData(sSql))
  16. End With

Now, if you want to get the value of the first column and the SubItem like the SellingPrice. This is how you do it by using the DoubleClick even of the Listview.

  1. Dim SellingPrice As Double
  2.  
  3. intProductDetailID = lvList.FocusedItem.Text
  4. SellingPrice = lvList.FocusedItem.SubItems(6).Text

Whatever row you have selected, it will always get the value of ProductDetailID and the SellingPrice column.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.