Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
965
Multi Colored Background in UltraWinGrid Cell
posted

Hello,

I'd like to know the best way to add anywhere from 1 to 4 background colors to an UltraWinGrid Cell. I'd also like the colors to export to Excel and PDF.

If I only need to apply one back color I can use

e.Layout.Bands(0).Columns(1).CellAppearance.BackColor = Color.LightYellow

If I need to apply multiple back colors I'd like to be able to split the background into 2, 3, or 4 equal sections and apply the additional colors, one per background section. For example if I wanted to apply Red and Yellow. The 1st half of the cell's background would be red and the 2nd half would be yellow.

Should I just make graphics and apply them to the background?

  • 469350
    Verified Answer
    Offline posted

    Hi,

    I think your idea about creating an Image or Bitmap and then applying it to the ImageBackground on the Appearance for the cell is the best one. That's the only one that will work for generating more than 2 colors in one cell background. It might be a bit heavy on memory usage, though. So I would recommend caching and re-using the same image whenever possible.

  • 53790
    posted

    Hello acozzi,

    There are different approaches to solve this. Here are few possible options:

    Option 1: Using  AppStyle.

    You could create your own style or using existing style with small modifications. If you choose this approach you could set desired Resourse (desired colors that you would like to see in the cell) to your GridCell. Also you could use Background images instead of Resources. Using this approach you could set one or more colors in the cells. One of advatntages of this approach is that you could create appStyle that you could apply to different grids in your application without write a code.

    Option 2: Using  CellAppearance Properties

    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BackColor = Color.Red;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BackColor2 = Color.Yellow;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BackGradientStyle = Infragistics.Win.GradientStyle.GlassRight20;
    ultraGrid1.DisplayLayout.Bands[0].Columns[1].CellAppearance.BackHatchStyle = Infragistics.Win.BackHatchStyle.ForwardDiagonal;

    By this way you could set two BackColors in the cell. Please take a look at the screenshot below

    Option 3: Using DrawFilter

    This is a custom approach. I made small sample for you. Please take a look at the code below and result in the screenshot

    ultraGrid1.DrawFilter =new MyDraw1();

     public class MyDraw1 : IUIElementDrawFilter
        {
            public bool DrawElement(DrawPhase drawPhase, ref UIElementDrawParams drawParams)
            {
                CellUIElement slot = drawParams.Element as CellUIElement;

                if (drawPhase == DrawPhase.AfterDrawElement && slot != null)
                {
                    drawParams.AppearanceData.AlphaLevel = 100;
                    drawParams.AppearanceData.BackColor = Color.Yellow;
                    drawParams.DrawBackColor(ref drawParams.AppearanceData, new Rectangle(new Point(slot.Rect.X, slot.Rect.Y), new Size(50, slot.Rect.Height)), new Rectangle(new Point(slot.Rect.X, slot.Rect.Y), new Size(50, slot.Rect.Height)), true);

                    drawParams.AppearanceData.BackColor = Color.Red;
                    drawParams.DrawBackColor(ref drawParams.AppearanceData, new Rectangle(new Point(slot.Rect.X + 50, slot.Rect.Y), new Size(50, slot.Rect.Height)), new Rectangle(new Point(slot.Rect.X+50, slot.Rect.Y), new Size(50, slot.Rect.Height)), true);
                }
                return false;
            }

            public DrawPhase GetPhasesToFilter(ref UIElementDrawParams drawParams)
            {
                CellUIElement slot = drawParams.Element as CellUIElement;
                if (slot != null) return DrawPhase.AfterDrawElement;
                else return DrawPhase.None;
            }
        }

    Let me know if you have any questions.

    Regards