473,396 Members | 1,997 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,396 software developers and data experts.

listView subitem click event.

The clcik event on the ListView control seems to trigger
off the item level ( the first column ). I would like to
be able to trap the click event on a particular subitem (
a specific column's row ). If possible, what do I do to
activate that 'cell' - thanks.

I thought that listView.LabelEdit = true; would enable me
to navigate into the cells or something like listView.items
[index].subitems[index].LabelEdit - but I did not see such
a property. Thanks for any hints and a good discussion on
this controls features
Nov 15 '05 #1
1 23635

Hi Andrew,

It seems that there are no event for you to handle the subitem click.
As a workaround, you can do the hit-test yourself.(In the ListView's
MouseDown event)

Sample code like this:
//first add org_i and org_j to the private member of the Form class with
initial value -1.
private int org_i=-1;
private int org_j=-1;

//the code below is in the ListView_MouseDown event.
//col_height is the height of the listview column header
int col_height=listView1.Items[0].Bounds.Height;

//org_i and org_j are the original clicked subitem.
if(org_i!=-1||org_j!=-1)
{
listView1.Items[org_j].UseItemStyleForSubItems =false;
listView1.Items[org_j].SubItems[org_i].BackColor=Color.White ;
}

//items_height and items_width are use for checking if the mouse click out
of all the items.
int items_height=0;
for(int item_count=0;item_count<listView1.Items.Count;item _count++)
{
items_height+=listView1.Items[item_count].Bounds.Height;
}
items_height+=col_height;

int items_width=0;
for(int col_count=0;col_count<listView1.Columns .Count ;col_count++)
{
items_width+=listView1.Columns [col_count].Width ;
}

//if the mouse clicks out of all the items or columns, just return.
if(e.X>=items_width||e.Y>=items_height)
{
return;
}

//i and j are the index of the subitem.
int i=0,j=0;
int width_len=listView1.Columns[0].Width;
int height_len=col_height+listView1.Items[0].Bounds.Height;
while(e.X >width_len)
{
i++;
width_len+=listView1.Columns[i].Width;
}

while(e.Y>height_len)
{
j++;
height_len+=listView1.Items[j].Bounds.Height ;
}

//change the clicked subitem's backcolor
listView1.Items[j].UseItemStyleForSubItems =false;
listView1.Items[j].SubItems[i].BackColor=Color.Blue ;

org_i=i;
org_j=j;

<Code End>

In the code, I just use the item[0]'s height as the column header's height
(int col_height=listView1.Items[0].Bounds.Height; ).
This is because I did not find a good way of retrieving the height of the
column header, I think this substitute way does make much difference.
But I think you can use LVM_GETCOLUMN to get the handle of the column, then
you can use Win32 function GetClientRect() to get its height.

It works well on my machine, if you have any questions please feel free to
let me know.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "andrewcw" <an************@boeing.com>
| Sender: "andrewcw" <an************@boeing.com>
| Subject: listView subitem click event.
| Date: Tue, 7 Oct 2003 15:26:12 -0700
| Lines: 11
| Message-ID: <0f****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcONIgNTlhz7GS68T32Y0fqpTvFtSA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:189676
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| The clcik event on the ListView control seems to trigger
| off the item level ( the first column ). I would like to
| be able to trap the click event on a particular subitem (
| a specific column's row ). If possible, what do I do to
| activate that 'cell' - thanks.
|
| I thought that listView.LabelEdit = true; would enable me
| to navigate into the cells or something like listView.items
| [index].subitems[index].LabelEdit - but I did not see such
| a property. Thanks for any hints and a good discussion on
| this controls features
|

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Richard | last post by:
Hi. How can I detect right-click on the ListView Column Headers? The click event doesn't do it. Thank you very much, Rick
0
by: Marie Mercier | last post by:
Hi, I would like to know when a listview is clicked in the background, instead of on an existing column. I noticed that the 'Click' event does not fire if there are no items in the listview....
1
by: active | last post by:
I've been working on a problem for a few days now. I do not get a Double-Click event fired for a ListView when I double click. I now find that if I double click with the right button it works OK....
2
by: Dino M. Buljubasic | last post by:
I have a list view with couple of items in it. When I left click on an item, a form opens displaying that item's properties. So that works fine. However, accidentally I found out that when I...
1
by: Tom | last post by:
Hi I have a listview with an event for mousemove and double click. Since implementing a handler for the mousemove event the double click event never gets fired, can anyone tell me how i should...
1
by: Jon | last post by:
Hi, How to add image to listview subitem? I can add image to the first column using ListViewItem("", 0) with a Imagelist. but cannot find a way to add to the subitem?? please help, many...
1
by: wilde | last post by:
hello, im new here in thescript.com im browsing the net looking for some forum which i could get some answers or idea for my question. i hope i can find one here......guys i want you to know...
4
by: raaman rai | last post by:
i wanna know if listview have the item double click event procedure in vb. pls enlighten me
2
by: lenniekuah | last post by:
Hello Friends, I am using C#NET2008, Window Application with LISTVIEW. I encounter an interesting problem while trying to retrieve 2 ListView SubItem column data of ORDERDATE and INVOICE for...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.