views:

119

answers:

1

well i have a program and i developed it by C# and WPF with Visual Studio 2010 ,

i have an window that contains a windows form datagridview (because of use of .Net Framework 3.5 for windows 7 support) i want to user can sort data in datagridview in any style that he/she wants and finally he/she can press enter on a cell of datagridview that he/she selected and then program open an detailed window about that row in datagridview , everything went well except one import thing , i use datasource of datagrid in my code like this :

if (gridView.SelectedCells.Count == 0) return;
            int index = gridView.SelectedCells[0].RowIndex - 1;

but this doesn't work well because datasource of datagridview did not change even a bit after all of sort working and that is still exactly like before ...

why ? and what can i do for updating this datasource after sorting or any better way to do this ?

Thanks All , Kind Regards ,

Omid

+1  A: 

It sounds like you're expecting the DataGridView to modify the datasource - which it won't (always) be doing in the case of a sort being performed.

Rather than getting your hands on the selected cell's RowIndex, if you want the underlying data item associated with that row, try getting the "DataBoundItem" from the Row object.

Will A
Hi Will , can you please give me a code example of what you say ?
omid