DataGrid - Detecting which cell was clicked

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Hello,
How would one go about detecting which row/column was clicked in a datagrid.
I'm sure it can be done but I can't figure it out.
Thanks
 
hi there

try something like this:

private void dataGridAdresse_Click(object sender,
System.Windows.Forms.MouseEventArgs e)
{
string strRowColumn = null;
Point pt = new Point(e.X, e.Y);
DataGrid.HitTestInfo hti = dataGridAdresse.HitTest(pt);
// right mouse
if(e.Button == MouseButtons.Right)
{
MessageBox.Show("Bitte mit der linken Maustaste anklicken," +"\n um das
Detail dieser Zeile anzuzeigen");
}
// left mouse
if(e.Button == MouseButtons.Left)
{
if(hti.Type == DataGrid.HitTestType.Cell)
{
strAdressenNummer = (dataGridAdresse[hti.Row, 0].ToString());
strRowColumn = "Column: " + hti.Column.ToString();
strRowColumn += ", Row: "+ hti.Row.ToString();
}
}
}

i hope this helps a bit to get on track !!

jonas knaus

(e-mail address removed)
 
You can also trap DataGrid.CurrentCell on mouseDown. It has two params,
RowNumber and COlumnNumber.
 
Thanks for the help guys. I'm going to look at both ways.
Thanks again...Have a good day!
 

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