Getting the current row of a datagrid

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
 
D

Dmytro Lapshyn [MVP]

Hello Randy,

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

Randy

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
 

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

Top