Getting the current row of a datagrid

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

Randy

Hello,
I've got an app that, when a certain row of a datagrid is clicked, it opens
another form (dialog box) where the row that was clicked on is populated
into the datagrid in the newly opened form. I get the current row by...

CurrencyManager xCM =
(CurrencyManager)dataGrid2.BindingContext[dataGrid2.DataSource,
dataGrid2.DataMember];
DataRowView xDRV = (DataRowView)xCM.Current;
currentDataGrid2Row = xDRV.Row;

Where currentDataGrid2Row is a DataRow. My problem is that I have the above
code in the MouseDown event of the main form datagrid. When I click on a row
and the above code is executed, it gets the row clicked previous to the last
one clicked. For example, if I click row 3 and then click row 4, it will
grab row 3. Then if I click row 6, it will get row 4 etc. I need a way to
get the absolute last clicked row.
Has anyone dealt with this before?

Thanks
 
Hello Randy,

The simplest solution should possibly be to move the code to the MouseUp
event.
 
Ok, Thanks Dmytro...I'll give it a shot.


Dmytro Lapshyn said:
Hello Randy,

The simplest solution should possibly be to move the code to the MouseUp
event.

--
Sincerely,
Dmytro Lapshyn [Visual Developer - Visual C# MVP]


Randy said:
Hello,
I've got an app that, when a certain row of a datagrid is clicked, it
opens another form (dialog box) where the row that was clicked on is
populated into the datagrid in the newly opened form. I get the current
row by...

CurrencyManager xCM =
(CurrencyManager)dataGrid2.BindingContext[dataGrid2.DataSource,
dataGrid2.DataMember];
DataRowView xDRV = (DataRowView)xCM.Current;
currentDataGrid2Row = xDRV.Row;

Where currentDataGrid2Row is a DataRow. My problem is that I have the
above code in the MouseDown event of the main form datagrid. When I click
on a row and the above code is executed, it gets the row clicked previous
to the last one clicked. For example, if I click row 3 and then click row
4, it will grab row 3. Then if I click row 6, it will get row 4 etc. I
need a way to get the absolute last clicked row.
Has anyone dealt with this before?

Thanks
 
Back
Top