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?).
How are you updating the cells? Are you just looping through all the rows and cells and updating them? What it sounds like is that the data source is sending a Reset notification to the grid, causing it to regenerate all of its rows, though I can't really say why this wouldn't happen until the grid has received focus.
As a side note, it will certainly be more performant to wrap your updates in a BeginUpdate/EndUpdate on the grid.
-Matt
I've tried value = and setvalue, and I'm using enter/exit edit mode. I've done it before and it worked, I think it's because I bind to a table for the values, but then add unbound check boxes to the grid for selection. The data from the bound object never gets changed or updated, only the checkboxes, expansions, and row activation get changed. Could the Focus() be calling the update and rebinding to the datasource?
The grid should never be rebinding the data source simply by getting focus, that would only generally happen when the data source itself sends a Reset notification. Are you using enter/exiteditmode events to update the values in all of the cells? Is there any chance that you can post a small sample that I could take a look at to see what you're doing? Another possibility is that you're changing the cell values in InitializeRow, overwriting the values in unbound columns and possible changing the Expanded state.
The only event I have code on for the grid is CellChanage.
As with most of my code, it's kinda cumbersome, but here is the code in the form button that sets the value:
oGrid.Focus();
{
oGrid.PerformAction(Infragistics.Win.UltraWinGrid.
UltraGridAction.EnterEditMode);
oRow.Cells[printField].Value =
true;
UltraGridAction.ExitEditMode);
}
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.
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.
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.