Hi! I have a grid view where I would like to get the cursor position from it when user fired event key up. I try to use code as below but it failed because the X and Y position from cursor.position is always out of range. Does anyone know how to solve it? Thanks.
private DataGridViewCell clickedCell;
Point cursorPos = dg_item.PointToClient(new Point(Cursor.Position.X, Cursor.Position.Y));
DataGridView.HitTestInfo hit = dg_item.HitTest(cursorPos.X, cursorPos.Y);
if (hit.Type == DataGridViewHitTestType.Cell)
{
MessageBox.Show("true");
clickedCell =
dg_item.Rows[hit.RowIndex].Cells[hit.ColumnIndex];
}
Niradhip ChakrabortyPosted Aug 6, 2008, 4:11 PM
it dispaly position of current cell:
DataGridViewCell cell = dataGridView1.CurrentCell;
Rectangle r= dataGridView1.GetCellDisplayRectangle(
dataGridView1.CurrentCell.ColumnIndex
, dataGridView1.CurrentCell.RowIndex , false);
MessageBox.Show(r.ToString());
KokPosted Aug 6, 2008, 8:51 AM
AlexPosted Aug 6, 2008, 7:29 AM
private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show(e.X + " , " + e.Y);
}