Alternating Row Style in the Gantt Chart Control
Details
Date:6/7/2010 5:20:20 PM
Product:ActiveGanttCSN Gantt Chart / Scheduler Component
Framework:.Net Framework 3.5
Version:2.8
User's Development Environment:C# Visual Studio 2008
Subject:Help with colors/styles
Question

All I want to do is have a treeview on the left with a white background. On the task side I would like to have alternating colors of dark grey and light grey as the background. I would like the grey colors on the right to fill the entire screen regardless of how many rows there are in the control. Also, I want the grey colors to stay the same regardless if the tree view is modified. I have tried several things the only thing I can seem to do is change the back color of the control. I even created an image and just tiled it. In the designer it looks great, however when I run it switches back to a plain white background. I don't have a problem adding tasks with the correct colors, its just setting up the control to have the correct background colors.

Answer

Answer:

This would be the code, taking: fHierarchicalProject as the basis, it works even when the treeview is collapsed or expanded:

In the fHierarchicalProject_Load include these two styles:


    oStyle = ActiveGanttCSNCtl1.Styles.Add("Rows1");
    oStyle.Appearance = E_STYLEAPPEARANCE.SA_FLAT;
    oStyle.BackColor = Color.LightGray;

    oStyle = ActiveGanttCSNCtl1.Styles.Add("Rows2");
    oStyle.Appearance = E_STYLEAPPEARANCE.SA_FLAT;
    oStyle.BackColor = Color.White;

And override the Control Draw Event.


private void ActiveGanttCSNCtl1_ControlDraw(object sender)
{
    int i;
    bool b = false;
    for (i = 1; i <= ActiveGanttCSNCtl1.Rows.Count; i++)
    {
        if (ActiveGanttCSNCtl1.Rows.Item(i.ToString()).Node.Hidden == false)
        {
            if (b == false)
            {
                ActiveGanttCSNCtl1.Rows.Item(i.ToString()).ClientAreaStyleIndex = "Rows1";
                ActiveGanttCSNCtl1.Rows.Item(i.ToString()).Node.BackColor = ActiveGanttCSNCtl1.Styles.Item("Rows1").BackColor;
                b = !b;
            }
            else
            {
                ActiveGanttCSNCtl1.Rows.Item(i.ToString()).ClientAreaStyleIndex = "Rows2";
                ActiveGanttCSNCtl1.Rows.Item(i.ToString()).Node.BackColor = ActiveGanttCSNCtl1.Styles.Item("Rows2").BackColor;
                b = !b;
            }
        }

    }
}

This will generate the following output:

If you only want the Rows to have an alternating background just eliminate the two Node.BackColor statements.

 

All trademarks are property of their respective holders, and are only used to directly describe the products and services being provided. Their use in no way indicates any relationship or endorsement between The Source Code Store LLC and the holders of said trademarks.