开发者

datasource of datagridview doesn't change after sorting

开发者 https://www.devze.com 2023-01-09 06:27 出处:网络
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

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/sh开发者_JS百科e 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消