473,387 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to get the selected subitem in a item LISTVIEW

Hi

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)
  7.  
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)
  3.  
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 24794
Hi,

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

Regards,
Smita
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.
e.g.:

‘ 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

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

Similar topics

1
by: Paddy | last post by:
I would like to do this: private void listView1_SelectedIndexChanged(etc) { // show the subitem of the item that was clicked } Please help. Paddy
4
by: Steve Murphy | last post by:
Is there a way to set a selected index for a Listview in a WinForms application? Thanks in advance, Steve Murphy
0
by: Webermax | last post by:
Hello, I want to retrieve the index of the selected item in a context menu synchronously. I coded something like this : MyContextMenu mcm; mcm = new MyContextMenu (); mcm.MenuItems.Add (new...
2
by: baret bonden | last post by:
Trying to return a selected listbox item to another form .tried lots of ways; defining public variables and passing those as well as textboxes ..I' m able to display the chosen item on it's form...
3
by: ljlevend2 | last post by:
I've noticed that selected items in a ListView are only highlighted if the control has focus. I find this to be highly undesirable because it can cause the control to behave differently than what...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
0
by: NeilS | last post by:
Hi all. I'm a newbie at VB.net, so please forgive me if this is well documented somewhere. I've found some sample code on the MS site for iterating over each unread item in the Inbox, and...
7
by: Mike Johnson | last post by:
How do I remove a item that's been selected from a listview? I'm using Visual Basic 2005 express edition. Thanks
4
by: Brett Wesoloski | last post by:
I am having a bit of a problem getting the current value of the checkbox list. I have tried using the selected value as I thought that would give me the current value of the check box but it...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.