Our users really like the conditional formatting option, but some of your grids have many columns and we would like a way for our users to set the same conditional formatting on multiple columns at once. We were going to create a custom tool in order to accomplish this, but I wanted to make sure it wasn't already available.
If it is not available is there a way to utilize your menu options outside the column header context menu? If possible we would also like to use the conditional formatting icons to show what is set on a group of columns.
Thanks,
Doug
Hello,
Our Conditional Formatting doesn't support applying rules for several columns at once. In general, the only way to accomplish this task is to duplicate FormatConditions for each column manually.
However, your final goal is not fully clear to me. Would you please describe it in greater detail? Do you want to move the Conditional Formatting menu from GridColumn's header context menu to a separate place? Or, do you want to use the Conditional Formatting Manager in a separate place? How do you want to separate rules for one column and rules for several columns? Should Conditional Formatting icons that indicate the "group" rules be shown in the Conditional Formatting Manager or in cells?
Thanks,
Kirill
We were going to try and keep things simple by having a conditional formatting window with a grid that has a row for each column (similar to what the column chooser is but in a grid). Then have a column for 'Conditional Formatting'.
The user can highlight multiple rows and click a button above the grid that would open the Conditional Formatting menu. Once the user selects the format they want the icon for the conditional format they selected would go into the 'Conditional Formatting' column for the highlighted rows.
Right now we only allow our users to access the built in formats and they cannot create a custom ones or use the conditional formatting manager.
Once the user exits the conditional formatting window we will manually apply the FormatConditions in code to the columns that were setup.
I may not have answered your questions directly but hopefully this explains what we are trying to accomplish better.
Thanks,
Doug
Hello,
If you want to apply an icon to a certain cell when a row meets a particular FormatCondition, you can override GridColumn's CellTemplate, add the Image control and bind its Source property using a MultiValueConverter. In this converter, you can check whether the current row meets the FormatCondition using ExpressionEvaluator and return a required icon. I have attached a simple sample to demonstrate the main idea of this approach. Another way is to change Image's Source property using DataTrigger or MultiDataTrigger with a similar converter, which will return a required "icon type".
As for the menu options, they are BarItems bound to corresponding TableViewCommands. So, if you want to use built-in formats, you can create your own Conditional Formatting menu and bind your menu item's commands to the corresponding TableViewCommands. You can see this approach in the attached sample. Do these solutions meet your requirements?
Thanks,
Kirill
Thanks for the example. It is in the right direction, but not quite what I was looking for. I would like to show the conditional formatting context menu you get from the header column (see attached screen shot) when you click the 'Apply condition' BarManager BarButtonItem you created in your example. However, I didn't see a TableViewCommand that allowed me to accomplish this and it would take a lot to build that menu from scratch using only the TableViewCommands (if its even possible to fully do this?).
The IconConverter in your example is going to be very helpful. I wasn't sure how to use your image library and this cleared it up.
Thanks,
Doug
Hello,
Our ConditionalFormatting menu from the column's header is created semi-manually in our internal code using our internal mechanisms. So, the only way to fully recreate this menu in a Bar is to create a class which implements the IConditionalFormattingDialogBuilder interface. Then, override the CreateBarButtonItem, CreateBarSplitButtonItem and CreateBarSubItem methods to provide the BarItem creation logic. Finally, create a ConditionalFormattingDialogDirector class instance using your custom class and call the ConditionalFormattingDialogDirector's CreateMenuItems method. I have attached a sample project to demonstrate this approach.
Thanks,
Kirill
This is excellent. The only thing I am noticing is that the Data Bars, Color Scales, Icon Sets and the Average Top/Bottom Rules menu options are missing. Are these not available?
Thanks,
Doug
Hello,
The Data Bars, Color Scales, Icon Sets and Average Top/Bottom Rules menu options are available not for all data types. For example, they aren't available for the string type. To show the ConditionalFormatting menu, you need to pass the corresponding column for which you want to apply conditional formatting. In this sample, the column used for the ConditionalFormatting menu is GridControl's CurrentColumn. When you run this sample, the current column has the string data type. That's why the Data Bars, Color Scales, Icon Sets and Average Top/Bottom Rules menu options aren't available in the ConditionalFormatting menu. However, when you select a numeric column, you will see these sets. I have attached a screencast to demonstrate this.
Thanks,
Kirill
Thanks for the explanation. I should have noticed that. I think this is exactly what I was looking for.
Thanks again for all the help,
Doug
You are welcome!
I have also collected all useful information and posted it to the answer. This may help other customers to find a solution to similar problems.
One last thing. I was able to get the icons for my grid from the BarButtonItem(s) created in the IConditionalFormattingDialogBuilder, but I am having difficulty obtaining the icons for the Data Bars, Color Scales and Icon Sets after the formatting is applied. Is there a way to use the converter you supplied with the name of the formatcondition chosen to get the icon somehow?
Hello,
If you need to find the corresponding format condition's icon, you can use TableView's PredefinedFormats, PredefinedDataBarFormats, PredefinedIconSetFormats and PredefinedColorScaleFormats collections. These collections are collections of FormatInfo objects. Each FormatInfo object's FormatName property contains the corresponding PredefinedFormatName value. So, you can find the required FormatInfo using FormatConditionBase' PredefinedFormatName property. Then, get FormatInfo's Icon property containing the corresponding format condition icon. For IconSetFormatCondition objects, you need to get FormatInfo's Format property, which contains an IconSetFormat object and use IconSetFormat's Elements property to obtain the required icons. I have modified the sample project to demonstrate this approach.
Thanks,
Kirill
Thanks, this works perfectly.
You are welcome!
I have implemented this solution in one of my views and it works great. I am currently adding it to another view, but for some reason the second view only builds menu items for Highlight Cells Rules and Clear Rules. Comparisons between the two views show they have the same logic for building the menu items. Any reason why one view would work and not the other? What is the driving factor behind which rule sets are used to build the menu items?
Thanks,
Doug
Hello,
It's difficult to determine the issue based on the provided information. Would you provide us with a code snippet demonstrating your problematic view or sample project?
Thanks,
Kirill
The logic is pretty embedded in our application and I tried to create a sample project but so far haven't been able to reproduce the issue in it. One thing I did notice is that for the view that works the column I am using to create the menu items for has a FieldType of Int32 and in the view that doesn't work the column show a FieldType of object. In both views I am using the FieldName property to bind the data and in both cases the bound data type is an int. I am confused why one view would get the type correctly and not the other.
I think I got this issue figured out. I was building the menu too soon, before the grid knew about its data and could determine what the column types were.
I'm happy to hear that you've resolved the issue.