How to get the last item of a WPF Datagrid

Nov 5, 2009 at 4:15 AM


Does anyone know how to get the last item of a WPF data grid. Also I want to get the selected row number.





Nov 21, 2009 at 1:00 AM



To get the index of the last item in the grid:  int lastIdx = myDataGrid.Items.Count - 1;

To get the last item, depending on how the datagrid is bound, (mine is to a list of business objects)

myObject gridItem = myDataGrid.Items[lastIdx] as myObject;

That should do it