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];
}

Alex38 reputationPosted Aug 6, 2008, 3:29 AM EDT
private void dataGridView1_MouseUp(object sender, MouseEventArgs e)
{
MessageBox.Show(e.X + " , " + e.Y);
}
Kok10 reputationPosted Aug 6, 2008, 4:51 AM EDT
Niradhip ChakrabortyRank #429 · 5.8K reputationPosted Aug 6, 2008, 12:11 PM EDT
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());