By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,156 Members | 1,004 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,156 IT Pros & Developers. It's quick & easy.

How to get the selected subitem in a item LISTVIEW

P: 1

I have a LISTVIEW where every item have 6 subitems (columns).
Expand|Select|Wrap|Line Numbers
  1. lstBrowse.Columns.Add("Col1", 150, HorizontalAlignment.Left)
  2. lstBrowse.Columns.Add("Col2", 150, HorizontalAlignment.Left)
  3. lstBrowse.Columns.Add("Col3", 150, HorizontalAlignment.Left)
  4. lstBrowse.Columns.Add("Col4", 150, HorizontalAlignment.Left)
  5. lstBrowse.Columns.Add("Col5", 150, HorizontalAlignment.Left)
  6. lstBrowse.Columns.Add("Col6", 150, HorizontalAlignment.Left)
I know how to get the selected item.
Expand|Select|Wrap|Line Numbers
  1. Dim SelectedOptions As ListView.SelectedListViewItemCollection = lstBrowse.SelectedItems
  2. Dim Item As ListViewItem = Me.lstBrowse.SelectedItems(0)
But I need to give the opportunity to the end user, to select a subitem.

I want to know how to get the selected subitem because I will fire different procedures for every subitem clicked in a item.

I will appreciate if anybody can show me, how to do that...

Thanks in advance,
Mar 4 '09 #1
Share this Question
Share on Google+
3 Replies

P: 1

Even I have this problem.
Please reply if somebody has found the solution.

Mar 10 '09 #2

P: 15
When the View property is set to "Details" you can't select a sub item because selecting an item selects the whole row.

I'm not sure about other view types.

You can, however, find the text value of a sub item.
Expand|Select|Wrap|Line Numbers
  1. Me.lstView1.SelectedItems(0).SubItems(1).Text
Mar 11 '09 #3

P: 4
I use this sequence of code:
It returns the row the user clicked in (as integer)
Further processing may be done in calling routine. In this case only a MsgBox is used now.

‘ within calling routine: (e.g. from the box-click-event, where parameters are sender and e)

Expand|Select|Wrap|Line Numbers
  1. Dim sel As ListViewItem = approofBox.GetItemAt(e.X, e.Y)
  2. MsgBox("row=" & getClickedRow(approofBox, e) & vbCrLf & " represents " & sel.SubItems(getClickedrow(approofBox, e)).Text & vbCrLf & sel.ToString)
... will show the clicked row, clicked item AND item in column(0)

' called routine:
Expand|Select|Wrap|Line Numbers
  1.  Function getClickedRow(ByVal box As System.Windows.Forms.ListView, ByVal e As System.Windows.Forms.MouseEventArgs) As Integer
  2.         Dim eex As Integer = 0
  3.         Dim appb As System.Windows.Forms.ColumnHeader
  4.         getClickedRow = -1
  5.         While (eex < e.X)
  6.             appb = box.Columns(getClickedRow + 1)
  7.             eex = eex + appb.width
  8.             getClickedRow = getClickedRow + 1
  9.         End While
  10.     End Function
Jun 18 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.