How to Get the Selected Value from Listview

Submitted by: 
Visitors have accessed this post 1394 times.

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.


Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.