Ron

Ron

  • NA
  • 44
  • 64.5k

Datagrid current Row/Value

Feb 28 2012 12:12 PM
This seems like a simple operation, but the solution has so far eluded me. I have a datagrid (I'm working in WPF) that is displaying data properly. I have some code in the previewkeydown event that I'd like to give me the value of the first cell in the grid that is currently selected. The following code works OK:

public static class DataGridHelper
{
    public static DataGridCell GetCell(DataGridCellInfo dataGridCellInfo)
    {
        var cellContent = dataGridCellInfo.Column.GetCellContent(dataGridCellInfo.Item);
        return (DataGridCell)cellContent.Parent;
    }
}

I display the cell content in a textbox using:

DataGridCell cell = DataGridHelper.GetCell(MyDataGrid.SelectedCells[0]);
txtMisc.Text = cell.ToString();

This is what displays:
System.Windows.Controls.DataGridCell: 1245

I only need the 1245

Is there a way to remove everything except the 1245?






Answers (3)