Hi,
I have a grid binding to a UltraDataSource. The data source table is intially empty. It is populated/updated by incoming real time data. Upon receiving a real time message, I'll update the data source table, and some cells backcolor based on the cell data. Somehow, the cell backcolor is changed properly sometimes. Is there any problem in the way I update the data/grid?
public void OnRealTimeDataIn(string xmlMessage)
{
int iRowIndex = -1;
//Code to extract useful information from the incoming data
//......
foreach (UltraDataRow row in this.UltraDataSource1.Rows)
if (string.Compare(row.GetCellValue("ID").ToString(), sIDIn, true) == 0)
iRowIndex = row.Index;
break;
}
if (iRowIndex == -1)//data doesn't exist in the table
UltraDataRow newRow = this.UltraDataSource1.Rows.Add();
//assign data
//
iRowIndex = newRow.Index;
else
UltraDataRow exitingRow = this.UltraDataSource1.Rows[iRowIndex];
//update cell values, and its child band values
//Generate backcolor based on some algo
//Set cell back color
this.WinGird1.Rows[rowIndex].Cells["State"].Appearance.BackColor = clrBackColor;
The other question I have is that after sorting the gird by clicking on the column header, does the data in the ultradatasource gets sorted as well? e.g. dataA is at row1 in datasource table, after sort, it is displayed at row3 in grid, is it also at row3 in the data source table?
Thank you.
You are setting the CellAppearance of the column. This will, of course affect all cells in the column. If you want to change the appearance on a single cell, then you need to set the Appearance of the cell.
The best place to do this is usually the InitializeRow event - the event is specifically designed for just this kind of thing where you want to color a cell based on it's value.
Check out the WinGrid Performance Guide.
There's some sample code under the last section ("Re-Use Appearances") that shows how to do this in the most efficient way.
I am changing the cell backcolor base on some condition. but its changing for complete column. I want to changes for some cells not for complete column. here the snapshot of code. please help me to fix the issue.
if (l_Dr != null && l_Dr.Length > 0) { gridItem.DisplayLayout.Bands[0].Columns[iRow].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.DropDownList; //gridItem.DisplayLayout.Bands[0].Columns["PRQ Date"].CellActivation = Activation.NoEdit; gridItem.DisplayLayout.Bands[0].Columns[iRow].CellActivation = Activation.ActivateOnly; //gridItem.DisplayLayout.Bands[0].Columns[iRow].CellAppearance.BackColor = Color.White; gridItem.DisplayLayout.Bands[0].Columns[iRow].ResetCellAppearance(); } else { gridItem.DisplayLayout.Bands[0].Columns[iRow].CellActivation = Activation.NoEdit; gridItem.DisplayLayout.Bands[0].Columns[iRow].CellAppearance.BackColor = Color.LightGray; //gridItem.DisplayLayout.Bands[0].Columns[iRow].CellAppearance.ForeColor = Color.Gray; //gridItem.Rows[oCellUI.Row.Index].Cells["ItemEditableInd"].Text }
I'm not sure. Can you reproduce this error? If so, you should Submit an incident to Infragistics Developer Support
I've tried to use InitializeRow event, however, occasionally the grid throw exception when I try to change the cell back color. What caused this exception?
System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object." Source="Infragistics2.Win.v7.3" StackTrace: at Infragistics.Win.UIElement.GetDescendant(Type type, Object[ contexts) at Infragistics.Win.UltraWinGrid.UltraGridCell.GetUIElement(RowScrollRegion rsr, ColScrollRegion csr, Boolean verifyElements) at Infragistics.Win.UltraWinGrid.GridItemBase.InvalidateItem(RowScrollRegion rsr, ColScrollRegion csr, Boolean recalcRects) at Infragistics.Win.UltraWinGrid.GridItemBase.InvalidateItemAllRegions(Boolean recalcRects) at Infragistics.Win.UltraWinGrid.UltraGridCell.InvalidateItemAllRegions(Boolean recalcRects, Boolean dirtyMergedCell) at Infragistics.Win.UltraWinGrid.UltraGridCell.OnSubObjectPropChanged(PropChangeInfo propChange) at Infragistics.Shared.SubObjectBase.NotifyPropChange(PropChangeInfo trigger) at Infragistics.Shared.SubObjectBase.NotifyPropChange(Enum propId) at Infragistics.Win.AppearanceData.set_BackColor(Color value) at Infragistics.Win.Appearance.set_BackColor(Color value) at TECH.Plugin.FVViewer.UpdateAppearance(UltraGridRow row) in E:\NET2005\Plugin\FVViewer\FVViewer.cs:line 584 at TECH.Plugin.FVViewer.gridInfo_InitializeRow(Object sender, InitializeRowEventArgs e) in E:\NET2005\Plugin\FVViewer\FVViewer.cs:line 496 at Infragistics.Win.UltraWinGrid.UltraGrid.OnInitializeRow(InitializeRowEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireEvent(GridEventIds id, EventArgs e) at Infragistics.Win.UltraWinGrid.UltraGrid.FireInitializeRow(InitializeRowEventArgs e) at Infragistics.Win.UltraWinGrid.UltraGridRow.FireInitializeRow() at Infragistics.Win.UltraWinGrid.UltraGridBand.DataSource_ItemChanged(Object sender, ItemChangedEventArgs ea) at System.Windows.Forms.CurrencyManager.OnItemChanged(ItemChangedEventArgs e)
To answer your second question first, the answer is no. The order of the rows in the grid does not affect the order of rows in the data source. It cannot, because not all data sources support sorting or moving rows.
Anyway, I'm not sure why this doesn't work sometimes. It might be for the same reason because you are using the row index. A better way to color a row or cell based on the contents is to use the InitializeRow event. This event will fire for each row any time anything in the row changes. So it's an ideal place to apply appearancesto a cell or row or to perform calculations on cells.
Also, make sure you have the latest Hot Fix.