Determining whether the user selected a different row on datagrid


is there a simple way to determine whether the user clicked on a different row inside the datagrid?


Who is Participating?
dsaboConnect With a Mentor Commented:
You could use the property currentrowindex of the datagrid and the event CurrentCellChanged. Also you need to add a variable to know if the selection is a new row or just a new cell.

int LastRow = 0;


private void grid1_CurrentCellChanged(object sender, System.EventArgs e)
    if(LastRow != grid1.CurrentRowIndex)
           LastRow = grid1.CurrentRowIndex;

           // ROW CHANGED--- wrtie your code here
Do you mean if someone clicks on a different row? whether they click update button or similar?

Well basically with most events in the Datagrid you have the arguements in the Event handler you can find out which row has been selected from that ....

e.Item.Cells[0] is the first cell data... 0 being the index of the cell...

This way for any type of command or event you can know if the row has been changed.
brdrokAuthor Commented:
thanks dsabo....

worked out pretty good.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.