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

Mouse Events ?

TM
My Windows Form application has a ListView control, it has 3 columns. I use
onMouseUp event to capture the user's x,y mouse coordinates. How do I use
these X & Y to find out the excact column and the row number of thew
ListView control so that I can retrieve an item in it.

Example: string ls=myListView.Items[???].ToString(); The ??? is the index
point to the list items.

TIA

Thomas
Nov 15 '05 #1
3 2470
Below code may help you,

private int X=0;
private int Y=0;
private int subItemSelected = 0 ;

public void ListView_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
li = this.GetItemAt(e.X , e.Y);
X = e.X ;
Y = e.Y ;
}

public void ListView_DoubleClick(object sender, System.EventArgs e)
{
int nStart = X ;
int spos = 0 ;
int epos = this.Columns[0].Width ;

for ( int i=0; i < this.Columns.Count ; i++)
{
if ( nStart > spos && nStart < epos )
{
subItemSelected = i ;
break;
}

spos = epos ;
epos += this.Columns[i+1].Width;
}
}
Console.WriteLine("SUB ITEM SELECTED = " +
li.SubItems[subItemSelected].Text);
subItemText = li.SubItems[subItemSelected].Text ;

string colName = this.Columns[subItemSelected].Text ;
}

Burke.

"TM" <Th**************@Yahoo.Com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
My Windows Form application has a ListView control, it has 3 columns. I use onMouseUp event to capture the user's x,y mouse coordinates. How do I use
these X & Y to find out the excact column and the row number of thew
ListView control so that I can retrieve an item in it.

Example: string ls=myListView.Items[???].ToString(); The ??? is the index
point to the list items.

TIA

Thomas

Nov 15 '05 #2
I'd use MouseDown rather than MouseUp, as I did in the code below. But if
you really need MouseUp just change it.

private void listView1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)

{

ListViewItem item = listView1.GetItemAt(e.X, e.Y);

if (item != null)

{

MessageBox.Show(item.GetType().ToString());

}

}

Hope this helps,

Dale
"TM" <Th**************@Yahoo.Com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
My Windows Form application has a ListView control, it has 3 columns. I use onMouseUp event to capture the user's x,y mouse coordinates. How do I use
these X & Y to find out the excact column and the row number of thew
ListView control so that I can retrieve an item in it.

Example: string ls=myListView.Items[???].ToString(); The ??? is the index
point to the list items.

TIA

Thomas

Nov 15 '05 #3
TM
Thanks Burke, that works great!

Thomas

"Burke ATILLA" <bu***@verisoft.com.tr> wrote in message
news:Op**************@TK2MSFTNGP12.phx.gbl...
Below code may help you,

private int X=0;
private int Y=0;
private int subItemSelected = 0 ;

public void ListView_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
li = this.GetItemAt(e.X , e.Y);
X = e.X ;
Y = e.Y ;
}

public void ListView_DoubleClick(object sender, System.EventArgs e)
{
int nStart = X ;
int spos = 0 ;
int epos = this.Columns[0].Width ;

for ( int i=0; i < this.Columns.Count ; i++)
{
if ( nStart > spos && nStart < epos )
{
subItemSelected = i ;
break;
}

spos = epos ;
epos += this.Columns[i+1].Width;
}
}
Console.WriteLine("SUB ITEM SELECTED = " +
li.SubItems[subItemSelected].Text);
subItemText = li.SubItems[subItemSelected].Text ;

string colName = this.Columns[subItemSelected].Text ;
}

Burke.

"TM" <Th**************@Yahoo.Com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
My Windows Form application has a ListView control, it has 3 columns. I

use
onMouseUp event to capture the user's x,y mouse coordinates. How do I use these X & Y to find out the excact column and the row number of thew
ListView control so that I can retrieve an item in it.

Example: string ls=myListView.Items[???].ToString(); The ??? is the index point to the list items.

TIA

Thomas


Nov 15 '05 #4

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

Similar topics

5
by: John Champaign | last post by:
Hi all, I'm working on an educational applet for a child with special needs. He's got a bit of a trick to make my life more difficult... To interact with the applet he needs to click on...
0
by: Stephen Williams | last post by:
I am migrating a VB 6 PictureBox control to VB.NET. In VB 6, this control modified its border style during the mouse down and up events to provide user feedback that it was selected. Once...
1
by: Jean-Gael GRICOURT | last post by:
I am trying to capture mouse events when entering and leaving a DIV layer. This test code works fine with IE 6.0 and Opera 7.21 but fails with Mozilla/Netscape. The strange thing is that the mouse...
3
by: red | last post by:
mouse events when the mouse is on a "child control" hi everyone; my problem: I have a userControl in this usercontrol, I have a child control (a button) when the mouse moves over the...
5
by: Bill Henning | last post by:
Does anyone know a good method of preventing keyboard and mouse events from interrupting processing? My situation is: 1) I need to track and handle all key and mouse events 2) I need to perform...
3
by: Rick Strahl [MVP] | last post by:
I'm working on an app that's using the WebBrowser control. I got the control working fine, hooking to the document object. But I've run into a major issue with hooking the Document events....
3
by: Charles Law | last post by:
In a user control, is it possible to replace the default mouse events with my own? In particular, I want the consumer of my control to get MouseMove events when the mouse is over my control, so...
2
by: bretth | last post by:
In a VB.Net Windows Forms application, I have a user control that handles mouse events. Another section of code programmatically adds a label to the control. I would like label to ignore all...
5
by: Adeel | last post by:
Hi group! I'm trying to learn C# on my own... I'd appreciate it very much if someone can help me out here. I have a basic form without any controls on it... I want to catch mouse clicks (both...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.