DataGridCell cell = dataGrid.GetCell(rowIndex, columnIndex); object value = cell.GetValue(DataGridCell.ContentProperty);
var selectedCells = myDataGrid.SelectedCells; foreach (var cell in selectedCells) { var value = cell.Column.GetCellContent(cell.Item).GetValue(TextBlock.TextProperty); }This code retrieves the values of the selected cells in a DataGrid and stores them in an object variable. It uses the GetCellContent method to retrieve the UI element that represents the value of the cell. The System.Windows.Controls.DataGrid is part of the WPF library.