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

SourceListListChanged event

Hi, I''m updating the cells in a column of my groupingdatagrid by changing the values in the underlying DataTable. That works fine, but I''d like to add some fn''ality to colour the cells according to whether they''ve changed up or down, numerically. I''d like to do this generically. So I need a class that detects changes in the underlying DataTable, and responds accordingly. The problem I''m hitting is that the event that I''m using to detect these changes (SourceListListChanged) only seems to tell me which row in the underlying IList has changed: void ggc_SourceListListChanged( object sender, TableListChangedEventArgs e ) { IListSource ils = ggc.DataSource as IListSource; if( ils != null ) { IList il = ils.GetList(); System.Diagnostics.Debug.WriteLine( "ggc_SourceListListChanged" ); System.Diagnostics.Debug.WriteLine( " ListChangedType: " + e.ListChangedType.ToString() ); System.Diagnostics.Debug.WriteLine( " OldIndex: " + e.OldIndex );//+ " [" + il[e.OldIndex].ToString() + "]" ); System.Diagnostics.Debug.WriteLine( " NewIndex: " + e.NewIndex + " [" + il[e.NewIndex].ToString() + "]" ); DataRowView drv = il[e.NewIndex]; } } Making no reference to the column that has changed. Furthermote, I need a way of going from the changed DataRowView object to an absolute x,y cell reference within the grid, so that my rendering code can determine which cells to draw specially. So: a) how can I tell when a specific column in a DataRowView has changed? b) how can I map a DataRowView and column index into a GridTableControlDrawCellEventArgs.Inner.RowIndex / GridTableControlDrawCellEventArgs.Inner.ColIndex pair, so that I can render a specific cell differently? Many thanks, DM

5 Replies

DM Dominic Morris November 15, 2004 11:21 AM UTC

Related to this: I would like to re-draw a single cell (on a timer). What''s the best way to accomplish this?


AD Administrator Syncfusion Team November 15, 2004 11:48 AM UTC

If you are using a DataTable datasource, a simpler way to do this is to handle TableControlPrepareViewStyleInfo and compare the current value of the record field to the orginal value (which you can get from the DataRow), and then color it if they are different.
private void gridGroupingControl1_TableControlPrepareViewStyleInfo(object sender, GridTableControlPrepareViewStyleInfoEventArgs e)
{
	GridTableCellStyleInfo style = e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex];
	if((style.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell 
		|| style.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell)
		&& style.TableCellIdentity.DisplayElement != null)
	{
		DataRowView drv = style.TableCellIdentity.DisplayElement.GetData() as DataRowView;
		if(drv != null && !drv.Row[style.TableCellIdentity.Column.Name, DataRowVersion.Original].Equals(style.CellValue))
		{
			//Console.WriteLine("******" + drv[style.TableCellIdentity.Column.Name]);
			e.Inner.Style.BackColor = Color.Red;
		}
	}
}


DM Dominic Morris November 15, 2004 11:56 AM UTC

Cool, looks good. Will try it now. Thanks Clay.


DM Dominic Morris November 15, 2004 12:37 PM UTC

Clay, I get the error: "There is no Original data to access." when I try this code. Google shows this to be an error associated with much confusion & despair. :(


AD Administrator Syncfusion Team November 15, 2004 04:36 PM UTC

After loading your DataTable, are you calling DataTable.AcceptChanges to set the row state of the DataTable?

Loader.
Live Chat Icon For mobile
Up arrow icon