473,396 Members | 1,968 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: How can I tell which subitem is clicked?

I have a form containing a ListView with four columns, creating a multi-cell
table. I want to have an event which can determine which cell in the table
is under the cursor when a double-click is done. The double-click event of
the ListView double-click event handler only passes in the sender object and
the EventArgs object. How can I figure out the specific cell where the click
occurred?

Peter Steele
CIENA Corp.
Nov 15 '05 #1
2 19216
Okay, so I decided to try something with the MouseDown event and do this:

ListViewItem cell = ListView1.GetItemAt(e.X, e.Y);

This gives me a reference to the correct row of the table but not the
subitem. In other words, this always gives me the cell at column 0. I want
to fine tune this so that I know the subitem the user has clicked on, which
could be the cell at any given column along that row. Is there a way to do
this?

"Peter Steele" <ps*****@ciena.com> wrote in message
news:uV**************@TK2MSFTNGP09.phx.gbl...
I have a form containing a ListView with four columns, creating a multi-cell table. I want to have an event which can determine which cell in the table
is under the cursor when a double-click is done. The double-click event of
the ListView double-click event handler only passes in the sender object and the EventArgs object. How can I figure out the specific cell where the click occurred?

Peter Steele
CIENA Corp.

Nov 15 '05 #2
On Mon, 16 Feb 2004 16:10:04 -0800, "Peter Steele" <ps*****@ciena.com>
wrote:
Okay, so I decided to try something with the MouseDown event and do this:

ListViewItem cell = ListView1.GetItemAt(e.X, e.Y);


A general note: For determining that someone's clicked on your
ListView you can simply use the SelectedIndexChanged (single click)
and ItemActivate (double click, configurable) events. You can get the
current row by examining the first element of
SelectedIndices/SelectedItems inside the event handler.

As for figuring out the column, that's something you'll have to do
yourself. Get the Columns collection, then the Width of each
ColumnHeader, then start adding up to see which point your mouse
cursor is at (the static property Cursor.Position returns the current
mouse cursor coordinates).

Note that Cursor.Position may be slightly changed from the click point
at the time you evaluate it so you might want to stick with the
MouseDown event for this particular purpose after all.
--
http://www.kynosarges.de
Nov 15 '05 #3

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

Similar topics

2
by: John Lauwers | last post by:
I know you can edit the first column of the listview control, is there a way to edit the second and/or the other columns? greets John
6
by: Richard | last post by:
Hi. I use a ListView to display data in tabular form. Each ListView row corresponds to a data record. The ListView Item of the record is the record key or code. Each SubItem in that row...
1
by: andrewcw | last post by:
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...
13
by: Maheshkumar.R | last post by:
hi groups, I have placed an listview control, i want to iterate thru the control and find the clicked event items. listView2.Items.Add(fname.ToString(), i); how i can perform the iteration...
6
by: Jack | last post by:
Hello, I've noticed through searching this group's previous posts that one can get the item the mouse is over in a listview control but I did not see how to get the subitem the mouse is over. Is...
4
by: Steph. | last post by:
I have a List view displaying data in Detail mode with several columns. How I can get the column index the user clicked on ? (when user click on an item inside the ListView, not on a column...
5
by: Martin Horn | last post by:
Hi all, I want to implement a listview with editable subitems and I assume the easiest way is to overlay a textbox over the item to be edited. With this in mind I have come up with: Using...
1
by: TheSteph | last post by:
Any way to find the Clicked SubItem in a ListView ? private int GetSubItemAtPos(ListView AListView, Point APoint) { int PositionCounter = 0; int TmpRelativeColIndex = -1; //Browse All Column...
3
by: luiggye | last post by:
Hi I have a LISTVIEW where every item have 6 subitems (columns). lstBrowse.Columns.Add("Col1", 150, HorizontalAlignment.Left) lstBrowse.Columns.Add("Col2", 150, HorizontalAlignment.Left)...
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:
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: 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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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.