Lobo
February 25th, 2005, 11:20 AM
Hi,
I catch the moushover-event and a datagrid is returned as sender. How can I tell over which cell (or string inside that cell) the mouse hovers? Eventargs are empty, and the sender doesn't seem to have that information.
Thank you!
Lobo
checksal
February 25th, 2005, 12:05 PM
using System.Windows.Forms;
public class DataGridToolTips : DataGrid
{
private ToolTip toolTip1;
private int hitRow;
private int hitCol;
public DataGridToolTips()
{
hitRow = -1;
hitCol = -1;
toolTip1 = new ToolTip();
toolTip1.InitialDelay = 1000;
MouseMove += new MouseEventHandler( HandleMouseMove );
}
private void HandleMouseMove( object sender, MouseEventArgs e )
{
DataGrid.HitTestInfo hti = HitTest( new Point( e.X, e.Y ) );
if ( hti.Type == DataGrid.HitTestType.Cell
&& ( hti.Row != hitRow || hti.Column != hitCol ) )
{ // new hit row
hitRow = hti.Row;
hitCol = hti.Column;
if ( toolTip1 != null && toolTip1.Active )
toolTip1.Active = false; // turn it off
toolTip1.SetToolTip( this, this[ hitRow, hitCol ].ToString() );
toolTip1.Active = true; // make it active so it can show itself
}
}
}