Hello,
I am using Infragistics 14.1 and have a feature where I highlight certain cells in a grid by changing the fore and back colors. Using the following code:
foreach ( UltraGridRow xRow in ugGrid.Rows ){ foreach ( UltraGridCell xCell in xRow.Cells ) { if ( Conditons are met ) { xCell.Appearance.ForeColor = Color.White; xCell.Appearance.BackColor = Color.Black; } }}
I have a clear button which I would like to have set the grid back to the original appearance however I have been unable to find anything that will override the cell appearances.
I've tried looping thru each row and setting the RowAppearance as well as using the ResetForeColor and ResetBackColor methods.
I know I could loop thru each cell and change the appearance of each cell but wanted to see if there was a better/easier way of doing it.
Thanks in advance!
If you are coloring the cells based on some criteria based on the value in the cells or some other cells in the row, then a better approach would be to simply use the InitializeRow event instead of looping.
Then you can reset the appearance on the cell whenever the conditions are not met, or clear the colors by setting a flag and then calling grid.Rows.Refresh(InitializeRow) to make InitializeRow fire again.
Hello Anthony,
Thank you for contacting Infragistics Support.
In order to reset the appearance of the cells you may add all changed cells to some data structure, e.g. List or HashSet. When the Clear button is clicked you can iterate your data structure and reset each cell appearance. After all cells are cleared you can clear the content of your data structure.
One more point. Please note applying an Appearance to a cell requires getting a reference to the UltraGridCell. This means that for each cell you specifically access, memory is being allocated and used and a new Appearance object is also being created. If you want to reduce the memory footprint of this type of operation, a better way to do this is to create the Appearance object that you need up front and then re-use it whenever needed. More about UltraGrid memory usage you may find by following the next link http://help.infragistics.com/Doc/WinForms/current/CLR4.0/?page=WinGrid_Memory_Usage.html
Please find attached a sample solution implementing this approach.
Please let me know if you need any further assistance.