• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

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?


1 Solution
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.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now