When I load a grid, the first row is highlighted. I only want it to be highlighted or activated once I click on it. Is there a way to deactivate this on load up but keep it when I do click on a row?
Hi,
The grid does not automatically activate a row. The grid's ActiveRow is synchronized with the current row of the CurrencyManager. So if the grid is showing up with an active row, it must be because the CurrencyManager is positioned to that row.
You can set SynchWithCurrencyManager to false on the grid and this will disable the synchronization. But keep in mind that if you do this, you can't rely on the CurrencyManager being in synch with the grid. This may not matter to you, depending on the needs of your application.
Another option might be to reset the grid.DisplayLayout.Override.ActiveRowAppearance and ActiveCellAppearance so that the ActiveRow doesn't appear highlighted. Then you can deal with Selected rows instead of the ActiveRow.
Hi Mike,
I'm having the same issue. I need the grid to show which row is active; I just don't want the grid to automatically select a row initially. I tried setting SyncWithCurrencyManager to false, but that didn't seem to change anything.
The call stack tells me the grid's ActiveRow property is being set by the RowsCollection.InitGroupByRows method. Reflector tells me that this method sets a private boolean field (inInitGroupByRows) to true which is set back to false at the end of the method. So, here's my solution. Is there a better way to do this that doesn't involve using reflection to get the value of a private field?
private void OnGridAfterRowActivate(object sender, EventArgs e) { if (this.IsGridInitializingGroupByRows() && this.Grid.ActiveRow != null) { this.Grid.ActiveRow = null; } }
private bool IsGridInitializingGroupByRows() { return (bool)this.Grid.Rows.GetType().InvokeMember("inInitGroupByRows", BindingFlags.GetField | BindingFlags.NonPublic | BindingFlags.Instance, null, this.Grid.Rows, null); }