Datagrid MouseDown event

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

Randy

Hello all,
I'm trying to capture the column and row of the datagrid cell clicked. I'm
have problems figuring this out. I think it is simple but eludes me.
I have a datagrid and a MouseDown event...

private void dataGrid1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
DataGrid dg = (DataGrid)sender;
ycolumn = dg.CurrentCell.ColumnNumber;
xrow = dg.CurrentCell.RowNumber;
label4.Text = ycolumn.ToString();
}

In label4 I'm just putting the column on the form so I can see what I
clicked. The problem is, that what ever column I click, label4 (and
therefore ycolumn) shows the very last column I clicked. For example, when
it first runs label4 has 0. If I click click column 3, label4 shows 0. Then
I click column 5, label4 then shows 3. I then click column 1, label4 now
shows 5. It's like it shows the last column. Does anyone know what I'm doing
wrong?
Thanks
 
Your current cell isn't current yet on Mouse Down. I think .HitTest will
work for you or you could change the event to CellChanged...

HTH

Bill
 
Back
Top