WPF Toolkit DataGrid SelectionChanged Getting Cell Value

后端 未结 5 852
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-09 00:13

Please help me, Im trying to get the value of Cell[0] from the selected row in a SelectionChangedEvent.

I am only managing to get lots of different Microsoft.Windows

5条回答
  •  萌比男神i
    2020-12-09 01:06

    Since you are using the "SelectionChanged", you can use the sender as a Data Grid:

    DataGrid dataGrid = sender as DataGrid;
    DataRowView rowView = dataGrid.SelectedItem as DataRowView;
    string myCellValue = rowView.Row[0].ToString(); /* 1st Column on selected Row */
    

    I tried the answers posted here and were good, but gave me problems when started to hide columns in the DataGrid. This one works for me even when hiding columns. Hope it works for you too.

提交回复
热议问题