I've searched for hours with no luck. I've got a button that changes the value for a cell in every row of a band in the grid. In order to get the values "stick" I have to focus the grid using Focus() or Select(). The problem I have is it redraws the grid and I lose all expansions and other changes. If I upate the values without focusing the grid everything looks good until you click on the grid, then all the values are gone (I'm guessing this is because the values don't get written back to the dataset?).
That was it! I put the buttons in a container object that rebound the datasource on validation. Man, I hate it when it's my fault! Thanks for all of your help.
The only time InitializeLayout should fire is if you're setting the DataSource yourself, so you should check to see if you're doing this anywhere else. Unfortunately, it's hard for me to say what would be causing this without seeing the project in action.
-Matt
I put a stop on Initialize Layout and it fires everytime oGrid.Focus() is called...
I'll check the initialize layout, but as far as setting the value, it really doesn't matter one way or the other because I can remove all the code except oGrid.Focus() and it still resets it.
Is there a particular reason that you need to cause the cells to go into edit mode when you update their values? Looking at your code, you're just causing the same cell to enter and exit edit mode while looping through the grid rows, since this depends on the ActiveCell of the grid. Furthermore, do you happen to be getting into the CellChange event recursively when you change the value? I would think that you should just be able to call SetCellValue directly without entering edit mode.
If the grid is in fact being re-bound, the InitializeLayout event would fire. If the grid is getting a Reset notification, the only event that would be fired is on the data source itself; in the case of an IBindingList, the ListChanged event could be checked.