Current filter:
                                You should refresh the page.
                                  • Hi,

                                    I am using the XRDesignRibbonForm with scripts disabled and I would like to give the ability to my users to alternate background colors on any band they choose such as a group header band or group footer bands.

                                    After trying to find a solution to this, I found that the most common method was writing a script...but since scripts are not safe and I want my users to be able to do this themselves, I would like to be able to handle this with a binding expression.

                                    Would it be possible to register a custom function that could get the index of the band passed to the function?
                                    For example, let's say I wanted to get the printed index of GroupFooter2
                                    Example of function syntax:

                                    Ideally if I had this type of function I could create a Background Color Expression and do something like this:
                                    Iif(GetBandIndex([ReportItems].[GroupFooter2]) % 2 == 0, 'Color1', 'Color2')

                                    Can something like this be done?

                                    Thanks,
                                    George

                                1 Solution

                                Creation Date Importance Sort by

                                Hello George,
                                Yes, in the meantime, the recommended solution to alternate group headers is to use the code-behind solution. We do have future plans to look for a possible way to avoid writing code and achieve this using expressions.

                                Currently, you can accomplish your task for the WinForms End-User Report Designer by implementing a custom function. See Expression Editor - How to implement a custom New Line and Format functions. Please see a sample project in the attachment. The main idea is to create a function that will accept a target group band. In the custom function's Evaluate method, check the group index (stored in a band's Tag property) and determine if a group is odd or even.

                                [C#]
                                public object Evaluate(params object[] operands) { Band groupBand = operands[0] as Band; if (String.IsNullOrEmpty(groupBand.Tag.ToString())) groupBand.Tag = 0; int counter = -1; Int32.TryParse(groupBand.Tag.ToString(), out counter); int result = counter % 2; counter++; groupBand.Tag = counter; return result == 1; }

                                I hope you'll find this example helpful.

                                A follow-up:
                                If the RepeatEveryPage option is enabled for a group band, it will be necessary to use the more complex logic and check the currently processed group field value. So, in this case, you need to modify the Evaluate method's code as follows:

                                [C#]
                                public object Evaluate(params object[] operands) { Band groupBand = operands[0] as Band; int counter = -1; int groupValue = -1; if (!String.IsNullOrEmpty(groupBand.Tag.ToString())) { KeyValuePair<int, object> tagValue = (KeyValuePair<int, object>)groupBand.Tag; counter = tagValue.Key; groupValue = Convert.ToInt32(tagValue.Value); } int currentGroupValue = Convert.ToInt32(groupBand.Report.GetCurrentColumnValue("CategoryID")); if (groupValue != currentGroupValue) { groupValue = currentGroupValue; counter++; } groupBand.Tag = new KeyValuePair<int, object>(counter, groupValue); return counter % 2 == 1; }
                                • George Hebert (WSI) 08.26.2019

                                  Hi Jannet,

                                  Thank you for the wonderful example.  I tested it, and it works great.

                                  Thanks,
                                  George

                                • Jannet (DevExpress Support) 08.27.2019

                                  My pleasure, George.

                                  In the meantime, I see that you have been using our reporting tools for a while and we're always curious as to what kind of tasks they help to achieve in real-world applications. Thus could you answer several questions regarding the use of our reporting tools?
                                  What vertical market does your product serve (healthcare, finance, etc.)?
                                  What kind of tasks you perform or issues you solve with the help of our reporting tools?
                                  What kind of reports do you mostly create (examples include invoices, a chart of accounts, profit/loss statements, sales reports, etc.)?
                                  The key functionality aspect of such tools, that is crucial for you and your business.

                                  P.S.I realize this may be a lot to ask, but please take a moment to rate our Reporting product on Capterra – the direct link to our listing is: https://www.capterra.com/p/181493/DevExpress-Reporting/. We will greatly appreciate any feedback.