468,740 Members | 2,146 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,740 developers. It's quick & easy.

How to get the selected subitem in a item LISTVIEW


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
3 22817

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

Mar 10 '09 #2
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
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.

Similar topics

1 post views Thread by Paddy | last post: by
4 posts views Thread by Steve Murphy | last post: by
reply views Thread by Webermax | last post: by
3 posts views Thread by ljlevend2 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.