Hi,
Within a WinForms UlraGrid, I am looking for a means (via code) to alter the appearance of an entire row, whenever a targeted column value meets a certain condition. For example, I already know that I can target the respect cell via the ConditionValueAppearance. The closest I could find to what might work is the ConditionAppearanceRow Class. Unfortunately you don't provide any code snippets to demonstrate how this class is hooked up with a given DisplayLayout Band.
In any case, I need this capability through code, so I can set the row appearance on the fly. If there is another way to do this, I am all ears.
Thanks,
Lacy
Hi Souvik,
DAIWATCS said:What I understood from Kelly's code is that, she is trying to set the back color of a cell to a particular value, depending on the cell value, but as per the code, now she is setting the entire appearance of the cell to a new appearance. Don't you think that it is an overhead, because appearance object has a lot other properties other than the back color and those are unnecessarily being assigned to the cell, thus degrading the performance a little?
No, not at all. It is much more efficient to create an Appearance object and then apply that appearance to object than it is to set a property on the appearance of those same objects.
For example, suppose you have 1000 rows in your grid. In the InitializeRow, you do something like this:
e.Row.Cells[0].Appearance.BackColor = Color.Red;
This means you will create 1000 Appearance objects. This is going to use up quite a chunk of memory.
And the resolution process for appearance of the cell is not any faster. The cell still has to look at it's own Appearance object and resolve the colors and other appearance settings whether you assign an appearance object to it or it uses it's own private instance of an appearance.
DAIWATCS said: By the way, I am using ultragrid for a program trading application and the grid is used as a order monitoring window (read only), and has to handle large amount of data (say around 50,000 rows), which are getting updated may be every 100ms. Moreover there is market data of the securities also, which get refreshed every 500ms. So if I do any cell formatting in InitializeRow event it will degraded the performance drastically. Can you please give me some tips of how to improve the performance? It would be helpful if you could post some code snippet, of how to set the forecolor of certain columns, based on the value in one column. Can you please shed some light also on the configuration of system that I should use for the application to run smoothly?
Have you read the WinGrid Performance Guide?
In a case like this where you have a very large number of rows and they are updated often, you might be better off using a DrawFilter. The DrawFilter is only triggered for UIElements that are actually on the screen. So this will save you quite a lot of processing time over InitializeRow - which fires for every row.
Hi Mike,
What I understood from Kelly's code is that, she is trying to set the back color of a cell to a particular value, depending on the cell value, but as per the code, now she is setting the entire appearance of the cell to a new appearance. Don't you think that it is an overhead, because appearance object has a lot other properties other than the back color and those are unnecessarily being assigned to the cell, thus degrading the performance a little?
By the way, I am using ultragrid for a program trading application and the grid is used as a order monitoring window (read only), and has to handle large amount of data (say around 50,000 rows), which are getting updated may be every 100ms. Moreover there is market data of the securities also, which get refreshed every 500ms. So if I do any cell formatting in InitializeRow event it will degraded the performance drastically. Can you please give me some tips of how to improve the performance? It would be helpful if you could post some code snippet, of how to set the forecolor of certain columns, based on the value in one column. Can you please shed some light also on the configuration of system that I should use for the application to run smoothly?
Regards,
Souvik
I really appreciate you taking the time to help all of us here on the boards ! ! !Thank you again for all of your helpful input! ~Kelly
Hi Kelly,
Yes, this looks a lot more efficient to me. The only minor inefficiency I see here is that you are calling GetCellValue with for the same column several times. It would probably be metter to call it once and store the value. But that's a very small thing and probably won't make any noticable difference.
Hi Mike,Creating global appearances did work. I tried to implement your suggestions, so does this now look more efficient?
Dim LightYellowApp, LightGreenApp, LightRedApp, LightGreyApp As New AppearanceLightYellowApp.BackColor = Me.LightYellowLightGreenApp.BackColor = Me.LightGreenLightRedApp.BackColor = Me.LightRedLightGreyApp.BackColor = Me.LightGreyRowName.Cells(MyCol.Key).Appearance = Me.LightRedAppPrivate Sub UltraGrid_InitializeLayout(sender, e) For Each MyCol As UltraGridColumn In .UltraGrid.DisplayLayout.Bands(0).Columns If IsNumeric(MyCol.Key) = True Then .UltraGrid.DisplayLayout.Bands(0).Columns(MyCol.Key).CellAppearance = Me.LightYellowApp End If NextEnd SubPrivate Sub UltraGrid_InitializeRow(sender, e) AddConditionalFormatting(e.Row, False)End SubPrivate Sub AddConditionalFormatting(ByRef RowName As UltraGridRow, ByVal IsAssignmentsGrid As Boolean) Dim CellValue As Decimal For Each MyCol As UltraGridColumn In RowName.Band.Columns If IsNumeric(MyCol.Key) Or MyCol.Key = "Total FTE" Then If IsAssignmentsGrid = True AndAlso MyCol.Key <> "Total FTE" AndAlso RowName.Cells(MyCol.Index + 2).Value = "Y" Then RowName.Cells(MyCol.Key).Appearance = Me.LightGreyApp Else ' not assignments grid, or is and it is the total fte column If (Not RowName.GetCellValue(MyCol) Is DBNull.Value) AndAlso RowName.GetCellValue(MyCol) <= 0 Then CellValue = RowName.GetCellValue(MyCol) If CellValue < 0 Then RowName.Cells(MyCol.Key).Appearance = Me.LightRedApp End If Else ' value > 0 or is null RowName.Cells(MyCol.Key).Appearance = Me.LightGreenApp End If End If End If NextEnd Sub
Thank you again for your time and assistance,Kelly