How can I capture rows changing in datagrid (winforms) when arrow up/down is pressed?

  • Thread starter Thread starter newsgroper
  • Start date Start date
N

newsgroper

I update a form with labels and text boxes when the user clicks on the
rowheader of my winforms datagrid. I notice that the user can move to
a new row using the arrow up/down keys. I currently update the form
using the click event of the datagrid. How can I update the form when
the user moves to a new row using the arrow keys? In other words, I
need to capture the arrow keys when the datagrid is active or when a
new row is selected. BTW, I am using C#, however, if a VB.Net
developer has a solution, please reply. I can always convert the
code.
 
Hi,

You could handle the "CurrentCellChanged" event for the datagrid. As the
user moves to a new row you can capture the rownumber
("DataGrid1.CurrentCell.RowNumber"). Upon subsequent traversal of rows the
captured rownumber can be checked with the current row number.

Your event handling might look something like the following:

intSelectedRow = -1;
DataGrid1_CurrentCellChanged()
{
if (intSelectedRow != DataGrid1.CurrentCell.RowNumber) {
///update the form here
}
/// Update the row number with the newly selected row
intSelectedRow = DataGrid1.CurrentCell.RowNumber;
}



Regards,
Sankalp
 
ah, right under my nose... i should have seen it.

thank you very much for your assistance.
 
Back
Top