I am trying to understand how to put to use the Conditional Formatting Dialog. There is a boolean value on each row of data that will indicate if a row in the UltraWinGrid should be highlighted or not. I opened the Conditional Formatting Dialog for the boolean value, created a True Condition and set the appearance the way I want it. Now how do I get that appearance to apply to a row?
Sam
Hi Sam,
Assuming that your grid is bound to the data source at design-time, then you shouldn't have to do anything else. You just add the condition and apply some properties to the Appearance for that condition and that's it.
If it's not working, then my best guess is that the grid is losing the layout from design-time to run-time. Maybe your code is loading a layout into the grid?
Mike,
Attached is a demo of what I am trying to do... This little app should show a lot of names, first and last, in a WinGrid. there is a third property on the person object called IsHighlighted. The objective is to highlight the two names, such that the background is yellow, when the IsHighlighted is true.
The idea is that when the user clicks the button at the bottom of the form, it will iterate through the data source flipping the IsHighlighted flag and the UltraGrid needs to update correctly, too.
I took a look at your sample and I don't see any ValueBasedAppearances (or any other appearances) applied by the sample.
In any case, I don't see any way to do what you want to do here using ValueBasedAppearances. The ValueBasedAppearance applies an appearance to a cell based on the value in that cell. I don't think you can apply an appearance to a cell based on the value of another cell in the row - unless maybe you use a formula condition and an UltraCalcManager.
If that's what you want to do, place an UltraCalcManager component on the form with the grid. Then you go into the grid designer and go to the ValueBasedAppearance property on either of the two name columns.
You click AddFormulaCondition and this will bring up the formula builder dialog. You have to write a formula that returns a boolean value. In this case, it's very simple - you just want the value of the IsHighlighted column. So your formula is:
[IsHighlighted]
Then you just set whatever properties you like on the Appearance for the conditionand repeat the process on the other column.
Note that this is not a very efficient way to do it. You will end up creating two identical appearances. Or more, if your real application has more than two columns to which you want the appearance to apply.
If you are concerned about efficiency, then it would be much better to simply use the InitializeRow event of the grid, examine the value of the IsHighlighted cell and apply an appearance to the row. There's more information about this in the WinGrid Performance Guide.
Efficiency is always a concern of mine, so thank you for the link, like others said in response there, great post!
The main thing I was looking for is data binding the whole row's appearance to a property, such that I would not have to write any additional code to manage the change of the appearance as the data changed. As the user interacts with the grid, the user is able to change the data such that the appearance of the whole row should change.
From what I can tell, I will have to have my own event handler looking for changes in the data, the go find the corresponding row in the grid, then change that lines appearance.
Question: Somewhere the UltraGrid has hooked the data source's PropertyChanged event. Is there any way to hook into that hook?
My thought process is: UltraGrid gets the PropertyChanged event, does it thing, in my case does nothing because it isn't a property that the UltraGrid knows anything about. Then the UltraGrid will pass the row and property information up to me, so I can change the appearance on just that one row. My code does not have to go figure out which UltraGrid row is associated with the data row that fired the PropertyChanged event.
scarleton said: The main thing I was looking for is data binding the whole row's appearance to a property, such that I would not have to write any additional code to manage the change of the appearance as the data changed. As the user interacts with the grid, the user is able to change the data such that the appearance of the whole row should change. From what I can tell, I will have to have my own event handler looking for changes in the data, the go find the corresponding row in the grid, then change that lines appearance.
No, you don't have to do that. If you put code in the InitializeRow event, then that is all you will need. The event fires any time any value in the row changes. The event is s specifically designed to do exactly what you are trying to do here.