Get The coordinates Point on MouseEnter Event

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I've a MouseEnter event on a dataGrid, and I want to know, if the mouse
entered column no. 0 or column no. 1 .

How can it be done?

Thanks,
Gidi.
 
Hi,
I think below code is what you looking for:
private void dataGrid1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)

{

System.Drawing.Point pt = new Point(e.X, e.Y);

DataGrid.HitTestInfo hti = dataGrid1.HitTest(pt);

if(hti.Type == DataGrid.HitTestType.Cell)

{

MessageBox.Show(dataGrid1[hti.Row, hti.Column].ToString());

}

else if(hti.Type == DataGrid.HitTestType.ColumnHeader)

{

MessageBox.Show(((DataView)
DataGrid1.DataSource).Table.Columns[hti.Column].ToString());

}

}
Although above code is for MouseUp, you can write simular code for
MouseDown or MouseEnter.
Ref:http://www.syncfusion.com/FAQ/WindowsForms/FAQ_c44c.aspx#q696q
 
I've a MouseEnter event on a dataGrid, and I want to know, if the mouse
If you just need the cell coordinates, then you can use this:

this.dataGridView.CellMouseDown += new
System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridView_CellMouseDown);

private void dataGridView_CellMouseDown(object sender,
DataGridViewCellMouseEventArgs e)
{
//Do some stuff with the retrieved values
int rowNumber = e.RowIndex;
int colNumber = e.ColumnIndex;

}

regards,
joachim
 
Correct me if I am wrong. I read that joachim wants to get the column on
onmouseenter, if there is such an event in the datagrid control. I'd start by
looking at the column object itself as it may have mouse events. Baring that
you should get the mouse coordinates in the event args I should think from a
mouseover event (again assuming there is one). With these coordinates you
might be able to test with a pointtoscreen type of method to find out which
area of the grid the mouse is over.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top