Solved

Selecting Subitems by Click - VB.Net

Posted on 2007-11-26
5
3,398 Views
Last Modified: 2013-11-26
Hi All,

I need to select a listviewitem subitem by clicking/double-clicking on it.

I have a listview with a number of columns in it, and I need to be able to perform a function etc by clicking a subitem.

I like the layout options that the listview gives e.g. Groups, Tiles or I would have used a grid control.

Thanks
0
Comment
Question by:nzfire
  • 3
  • 2
5 Comments
 
LVL 48

Accepted Solution

by:
jpaulino earned 500 total points
ID: 20354087
You can do this to check what column/subitem was clicked. It just have to adapt it to your needs.

        Dim colstart As Integer = 0
        Dim colend As Integer = 0
        Dim x As Integer

        For x = 0 To (ListView1.Columns.Count - 1)
            colend = colend + ListView1.Columns(x).Width
            If colstart <= e.X And e.X <= colend Then
                Label1.Text = "Column clicked: " & x + 1
                Exit For
            End If
            colstart = colstart + ListView1.Columns(x).Width
        Next
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 20354097
But why don't you use a datagridview ?
0
 
LVL 1

Author Comment

by:nzfire
ID: 20354174
Hi jpaulino,

Thanks for the reply. As I mentioned in the Q, I like the layour that the listview gives in terms of creating groups etc. I don't know if this is possible in the datagridview.......

In your reply, how would I determine the item property though...i.e. the selected item?
0
 
LVL 48

Expert Comment

by:jpaulino
ID: 20354251
Thats more difficult to calculate!

If set the listview fullrowselect = true when you right click on the item will select him.
0
 
LVL 1

Author Comment

by:nzfire
ID: 20354277
Ok, this sounds more difficult than I thought.

I didn't want to do a full row select as I am displaying different backcolours for the subitems...maybe I will just have to live with the fact that I can't LOL!!!

I'll leave this q up to see if there is any more response
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now