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

mouse position in datagrid during MouseHover?

Hi,
How can you determine which cell the mouse is positioned over during the
mousehover event?
Thanks so much!
Mel
Nov 17 '05 #1
2 8763
You can grab the mouse positon (Control.MousePosition) in the MouseHover
event handler, translate the coordinates into something appropriate to the
DataGrid (dataGrid1.PointToClient()), determine the portion of the DataGrid
over which the mouse is hovering (dataGrid1.HitTest()), and then examine the
HitTestInfo that is returned to determine if the mouse is over a cell and,
if so, which cell.

private void dataGrid1_MouseHover(object sender, System.EventArgs e)
{
DataGrid grid = (DataGrid)sender;
Point clientPos = grid.PointToClient(Control.MousePosition);
DataGrid.HitTestInfo hitInfo = grid.HitTest(clientPos);
if (hitInfo.Type == DataGrid.HitTestType.Cell)
{
// this.dataGrid1[hitInfo.Row, hitInfo.Column]
}
}

--
Tim Wilson
..NET Compact Framework MVP

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
Hi,
How can you determine which cell the mouse is positioned over during the
mousehover event?
Thanks so much!
Mel

Nov 17 '05 #2
Thanks so much!
Mel

"Tim Wilson" wrote:
You can grab the mouse positon (Control.MousePosition) in the MouseHover
event handler, translate the coordinates into something appropriate to the
DataGrid (dataGrid1.PointToClient()), determine the portion of the DataGrid
over which the mouse is hovering (dataGrid1.HitTest()), and then examine the
HitTestInfo that is returned to determine if the mouse is over a cell and,
if so, which cell.

private void dataGrid1_MouseHover(object sender, System.EventArgs e)
{
DataGrid grid = (DataGrid)sender;
Point clientPos = grid.PointToClient(Control.MousePosition);
DataGrid.HitTestInfo hitInfo = grid.HitTest(clientPos);
if (hitInfo.Type == DataGrid.HitTestType.Cell)
{
// this.dataGrid1[hitInfo.Row, hitInfo.Column]
}
}

--
Tim Wilson
..NET Compact Framework MVP

"melanieab" <me*******@discussions.microsoft.com> wrote in message
news:FF**********************************@microsof t.com...
Hi,
How can you determine which cell the mouse is positioned over during the
mousehover event?
Thanks so much!
Mel


Nov 17 '05 #3

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

Similar topics

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...
5
by: gsb | last post by:
I track the mouse location like this code: function mousePos(e) { var p = new Object(); if(e) { p.x = e.pageX; p.y = e.pageY; } else { p.x = event.x; p.y = event.y; } ... (show) }...
3
by: jcrouse | last post by:
I have created a form designer type application (with a lot of you peoples helpJ). It has label controls that are draggable at runtime. The user is also allowed to change some properties such as...
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...
2
by: Saber | last post by:
glb is a global string, I want when moving mouse to a picturebox, change border style of picturebox. the code shown below do that but MouseLeave event fires less than a second after MouseHover,...
1
by: DaveS | last post by:
I am trying to capture the mouse click position in a datagrid but I get the following compilation error: Compiler Error Message: BC30002: Type 'System.Windows.Forms.MouseEventArgs' is not...
1
by: Emanuel | last post by:
I am trying to make a little diagramming app in C# with the 1.1 Framework (currently our standard here at work, will be upgrading to 2005 sometime in the next couple of months). I want to allow...
1
by: wanwan | last post by:
I'm trying to get the cursor changed to a hand whenever it stops in the form, and have it changed back to default whenever the mouse moves. So the common sense is to use the mousehover and...
5
by: kimiraikkonen | last post by:
Hi, I couldn't find a necessary class which shows when mouse hovers on a link in Webbrowser control. Think of there's a status bar(text), when mouse comes on a link, the URL must be shown in...
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
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...
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...

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.