WPF Toolkit DataGrid SelectionChanged Getting Cell Value

后端 未结 5 880
爱一瞬间的悲伤
爱一瞬间的悲伤 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条回答
  •  青春惊慌失措
    2020-12-09 00:54

    Less code, and it works.

    private void datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            DataGrid dataGrid = sender as DataGrid;
            DataGridRow row = (DataGridRow)dataGrid.ItemContainerGenerator.ContainerFromIndex(dataGrid.SelectedIndex);
            DataGridCell RowColumn = dataGrid.Columns[ColumnIndex].GetCellContent(row).Parent as DataGridCell;
            string CellValue = ((TextBlock)RowColumn.Content).Text;
        }
    

    ColumnIndex is the index of the column you want to know.

提交回复
热议问题