We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

SavedCellsInfo empty in CellsChanged method

I'm trying to get a list of Cells, or a single cell, that has changed in the CellsChanged method. HOwever, when I change the contents of a cell (via keyboard input), the method runs, but SavedCellsInfo is empty. E.Range does contain the changed cell's location. Any ideas? Eric

6 Replies

AD Administrator Syncfusion Team August 14, 2003 08:12 PM UTC

SavedCellsInfo is only populated if the grid's undo support is turned on. It is used by the grid in order to be able to undo these changes if necessary. You can get the list of changed cells from the range object. If you want the old values, you can set: Me.GridDataBoundGrid1.Model.CommandStack.Enabled = True then SaveCellsInfo should be non-empty.


ER ERobishaw August 15, 2003 02:07 AM UTC

I'm trying to avoid the CommandStack, b/c it saves way more than I need... in fact, that's the whole reason I was using SavedCellsInfo...I created my own simple CommandStack that only saves Text changes to cells. So...I was thinking I could use CellsChanging, but I can't figure out how to get the old values during that method, although they must be there, because if I set e.Cancel=true, then they are reverted. If the value is there internally, is there a public property that will return the old value as well? If not, I'll look for another way to go about this. Maybe there's a way to keep the CommandStack from saving virtually ALL changes... but I haven't figured it out yet. Thanks Eric > SavedCellsInfo is only populated if the grid's undo support is turned on. It is used by the grid in order to be able to undo these changes if necessary. You can get the list of changed cells from the range object. > > If you want the old values, you can set: > > Me.GridDataBoundGrid1.Model.CommandStack.Enabled = True > > then SaveCellsInfo should be non-empty.


AD Administrator Syncfusion Team August 15, 2003 04:26 AM UTC

In CellsChanging, you can get the old values directly from the grid through indexes, looping through the range object. In CellsChanged, the values in the grid have already been modified.


ER ERobishaw August 15, 2003 12:42 PM UTC

Doesn't hold true for me. I thought that same thing...but when I check the indexer value or text properties, it returns the new value/text. Example below: private void gridControl1_CellsChanging(object sender, Syncfusion.Windows.Forms.Grid.GridCellsChangingEventArgs e) { int RowIndex, ColIndex; string oldText=""; foreach (GridStyleInfo Style in e.CellsInfo) { RowIndex = Style.CellIdentity.RowIndex; ColIndex = Style.CellIdentity.ColIndex; oldText = gridControl1[RowIndex, ColIndex].Text); //always contains new value, not old } } > In CellsChanging, you can get the old values directly from the grid through indexes, looping through the range object. In CellsChanged, the values in the grid have already been modified.


AD Administrator Syncfusion Team August 15, 2003 01:33 PM UTC

You are right, I was wrong. There is a technical reason this works the way it does. The grid maintains a volatile cache of recently used style object for optimization purposes. So, in this situation a new style object for this new value has been created and is in this volatile cache. So, when you use grid[row,col] to reference a style, the grid retrieves this cached value instead of accessing the GridData object to retrieved the stored value. So, at this point, the new value appears to be stored in teh grid, but it really is only cached in teh volatile data store. The code below will retrieve the old value directly from the grid's GridData object as it is still there. I suspect your code would work if you called gridControl1.ResetVolatileData so the cache values are flushed, an dthe grid has to go to its GridData object to retrieve the data. But I am not sure if there are any side effects of calling ResetVolatileData at this point. Getting the data directly from the GridData object may be safer.
private void gridControl1_CellsChanging(object sender, GridCellsChangingEventArgs e)
{
	int row, col;
	GridData data = this.gridControl1.Data;
	bool b = e.Range.GetFirstCell(out row, out col);
	while(b)
	{
		string oldValue = "";
		if(data[row, col] != null)
		{
			GridStyleInfo style = new GridStyleInfo(data[row, col]);
			oldValue = style.Text;
			Console.WriteLine("({0},{1})=[{2}]   ", row, col, oldValue);
		}
		b = e.Range.GetNextCell(ref row, ref col);
	}
}


ER ERobishaw August 15, 2003 06:55 PM UTC

Thank-you very much. I can't get over the level of support you guys provide...phenomenal. Thanks Eric

Loader.
Live Chat Icon For mobile
Up arrow icon