WPF: how to enable DataGrid ID cells in first column editable when highlight it from code?

  • Thread starter Thread starter Jane Jie Chen
  • Start date Start date
J

Jane Jie Chen

Guest
Our application is WPF application. In a page, there are two controls.

one control is WPF DataGrid which include 5 columns. Only first and last columns are editable.

First column represent ID. Fifth column represents comment. DataGrid includes 96 rows.

Another control is plate which include 96 wells and displays as 8 rows X 12 columns = 96 wells.

when we click on one well in plate control, it automatically highlight related row in the DataGrid control with the same ID.

if click the first column highlight ID cell, it does not show the cell as editable. we have to click the second time to make it editable (see the cursor shows on the highlight ID cell).

We need a way that if DataGrid row is highlight, click the first cell in that row to allow to type right way.

We have added following event in DataGrid.

DataGridCell.Selected="DataGrid_CellGotFocus"

private void DataGrid_CellGotFocus(object sender, RoutedEventArgs e)
{
// Lookup for the source to be DataGridCell
if (e.OriginalSource.GetType() == typeof(DataGridCell))
{
// Starts the Edit on the row;
DataGrid grd = (DataGrid)sender;
grd.BeginEdit(e);
Debug.Print("DataGrid_CellGotFocus: " + e.OriginalSource.ToString());
}
}

If the ID cell is in editable mode, click next ID cell before or after, it makes the next selected cell editable right way.

However, if the focus is on the plate control, first time click the ID cell which is highlight, it does not show as editable and we have to click second time.

When highlight a row in DataGrird, it calls above event for each highlight cells.

we only needs to tell if it first column cell and then set it as Editable.

Does anyone know how to fix this, thx!

Continue reading...
 
Back
Top