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:
- With lvList
- .View = View.Details
- .FullRowSelect = True
- .GridLines = True
- .Columns.Add("ProductDetailID", 0)
- .Columns.Add("Category", 100)
- .Columns.Add("Brand", 100)
- .Columns.Add("Description", 250)
- .Columns.Add("U/M", 100)
- .Columns.Add("Qty On Hand", 100, HorizontalAlignment.Right)
- .Columns.Add("Selling Price", 100, HorizontalAlignment.Right)
- FillListView(lvList, GetData(sSql))
- 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.
- Dim SellingPrice As Double
- intProductDetailID = lvList.FocusedItem.Text
- SellingPrice = lvList.FocusedItem.SubItems(6).Text
Whatever row you have selected, it will always get the value of ProductDetailID and the SellingPrice column.