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