WPF Datagrid Get Selected Cell Value

前端 未结 12 2102
遇见更好的自我
遇见更好的自我 2020-11-30 08:47

I want to get value for selected cell in datagrid , please anyone tell how to do this. i used SelectedCell changed event , how can i do that?

dataGrid1.Curre         


        
12条回答
  •  广开言路
    2020-11-30 09:36

    When I faced this problem, I approached it like this: I created a DataRowView, grabbed the column index, and then used that in the row's ItemArray

    DataRowView dataRow = (DataRowView)dataGrid1.SelectedItem;
    int index = dataGrid1.CurrentCell.Column.DisplayIndex;
    string cellValue = dataRow.Row.ItemArray[index].ToString();
    

提交回复
热议问题