Hello,
I will set the active cell with following program code:
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e) { dg.Rows[0].Cells[1].IsActive = true; }
And I become a NullReferenceException. With the debugger I can see this cell with data.
Following program code with another row works correct:
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e) { dg.Rows[1].Cells[0].IsActive = true; }
Can you help me, please.
Hi,
I'd recommend using the Key of your column to make sure you're targeting the correct column.
dg.Rows[0].Cells["MyColumn"].IsActive = true;
I noticed that your second line of code, uses a different cell, which could mean that maybe Cells[1] is a hidden column, or maybe you only have one column. It's always safer to use the Column keys, as it ensure you're working with the column you intended.
Hope this helps,
-SteveZ
Hi SteveZ,
it's the same problem.
I've a grid with 2 rows and 2 columns and I can't set a cell active in the 2nd column.
When I use a debugger and bevor run the error code line I can see the 2nd column in the debugger. The property "IsActive" is false. I run the code line, I become a NullReferenceException and the debugger show me a changed property "IsActive=true". Why ?
Thomas
Hi Thomas,
I'm not sure. This shouldn't be happening.
Do you have a sample you can attach to this thread, so I can look into this further?
Hi Steve,
in the attachment you can see my sample.
Sure.
Assuming you have at least one data row available at Load time, you can do the following.
void Page2_Loaded(object sender, RoutedEventArgs e)
{
((RowsManager)this.DataGrid1.Rows[0].Manager).AddNewRowTop.Cells[0].IsActive = true;
}
is there a way to do this if you are using the Add New Row Feature? ie set the 'Add New Row' to active when page loaded?
Steve,
thanks for your workaround.
Thomas,
Thanks for the sample.
Essentially, whats happening, is you have IsOnCellActiveEditingEnabled turned on. And when the control loads, you set the cell as active, which tells the grid to put it in edit mode, however, at that point, we haven't even fully loaded, so its not even possible to create controls for the Cells and Rows.
It is a bug, i wrote it up, and it'll be fixed in the next SR. However, you can easily get around this for now.
So, to get around it, you need to delay setting the IsOnCellActiveEditingEnabled, until after you set the ActiveCell.
So, remove it from the xaml, and use the following code:
private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
dg.Rows[0].Cells[1].IsActive = true;
dg.EditingSettings.IsOnCellActiveEditingEnabled = true;
Thanks for the report, and I hope this helps,