This is a migrated thread and some comments may be shown as answers.

Change Backcolor of GraphicalView Summary Item

1 Answer 57 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 21 Jan 2015, 03:19 PM
Hi,
How can the GraphicalView Summary Item backcolor be changed?  I tried handling the GraphicalViewItemFormatting event and can change Task items using
e.ItemElement.TaskElement.BackColor but this had no effect on Summary items and I could not a reference to the SummaryItem in e or e.item.
Thanks,
John

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 24 Jan 2015, 01:05 PM
Hi John,

Thank you for writing.

As you have tried yourself you would need to subscribe to GraphicalViewItemFormatting event.
I have prepared an example in which I am setting color of the GanttViewSummaryItemElement as well as its GanttGraphicalViewBaseTaskElement.
Please see my code snippet below:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineStart = new DateTime(2010, 10, 9);
        this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineEnd = new DateTime(2010, 10, 30);        
        this.FillGanttViewWithData();
        this.radGanttView1.GraphicalViewItemFormatting += radGanttView1_GraphicalViewItemFormatting;
    }
     
    private void radGanttView1_GraphicalViewItemFormatting(object sender, GanttViewGraphicalViewItemFormattingEventArgs e)
    {
        GanttViewSummaryItemElement summaryItem = e.ItemElement as GanttViewSummaryItemElement;
        if (summaryItem != null)
        {
            //set color of the GanttViewSummaryItemElement
            summaryItem.BackColor = Color.Green;
 
            GanttGraphicalViewBaseTaskElement taskElement = summaryItem.TaskElement;
            //set color of all the summary elements in the GnttView
            foreach (var el in taskElement.Children)
            {
                if (el is GanttViewSummaryLeftElement)
                {
                    ((GanttViewSummaryLeftElement)el).BackColor = Color.Cyan;
                }
                else if (el is GanttViewSummaryRightElement)
                {
                    ((GanttViewSummaryRightElement)el).BackColor = Color.Cyan;
                }
                else if (el is GanttViewSummaryMiddleElement)
                {
                    ((GanttViewSummaryMiddleElement)el).BackColor = Color.Cyan;
                }
                else if (el is SummaryProgressIndicatorElement)
                {
                    ((SummaryProgressIndicatorElement)el).BackColor = Color.Yellow;
                }
            }
        }
    }
 
    private void FillGanttViewWithData()
        {
            //setup data items
            GanttViewDataItem item1 = new GanttViewDataItem();
            item1.Start = new DateTime(2010, 10, 10);
            item1.End = new DateTime(2010, 10, 15);
            item1.Progress = 30m;
            item1.Title = "Summary task.1. title";
 
            GanttViewDataItem subitem11 = new GanttViewDataItem();
            subitem11.Start = new DateTime(2010, 10, 10);
            subitem11.End = new DateTime(2010, 10, 12);
            subitem11.Progress = 10m;
            subitem11.Title = "Sub-task.1.1 title";
 
            GanttViewDataItem subitem12 = new GanttViewDataItem();
            subitem12.Start = new DateTime(2010, 10, 12);
            subitem12.End = new DateTime(2010, 10, 15);
            subitem12.Progress = 20m;
            subitem12.Title = "Sub-task.1.2 title";
 
            //add subitems
            item1.Items.Add(subitem11);
            item1.Items.Add(subitem12);
 
            this.radGanttView1.Items.Add(item1);
 
            GanttViewDataItem item2 = new GanttViewDataItem();
            item2.Start = new DateTime(2010, 10, 12);
            item2.End = new DateTime(2010, 10, 18);
            item2.Progress = 40m;
            item2.Title = "Summary task.2. title";
 
            GanttViewDataItem subitem21 = new GanttViewDataItem();
            subitem21.Start = new DateTime(2010, 10, 12);
            subitem21.End = new DateTime(2010, 10, 13);
            subitem21.Progress = 10m;
            subitem21.Title = "Sub-task.2.1 title";
 
            GanttViewDataItem subitem22 = new GanttViewDataItem();
            subitem22.Start = new DateTime(2010, 10, 13);
            subitem22.End = new DateTime(2010, 10, 18);
            subitem22.Progress = 30m;
            subitem22.Title = "Sub-task.2.2 title";
 
            GanttViewDataItem subitem23 = new GanttViewDataItem();
            subitem23.Start = new DateTime(2010, 10, 18);
            subitem23.End = new DateTime(2010, 10, 18);
            subitem23.Title = "Sub-task.2.3 title";
 
            //add subitems
            item2.Items.Add(subitem21);
            item2.Items.Add(subitem22);
            item2.Items.Add(subitem23);
 
            this.radGanttView1.Items.Add(item2);
 
            //add links between items
            GanttViewLinkDataItem link1 = new GanttViewLinkDataItem();
            link1.StartItem = subitem11;
            link1.EndItem = subitem12;
            link1.LinkType = TasksLinkType.FinishToStart;
            this.radGanttView1.Links.Add(link1);
 
            GanttViewLinkDataItem link2 = new GanttViewLinkDataItem();
            link2.StartItem = subitem21;
            link2.EndItem = subitem22;
            link2.LinkType = TasksLinkType.StartToStart;
            this.radGanttView1.Links.Add(link2);
 
            GanttViewLinkDataItem link3 = new GanttViewLinkDataItem();
            link3.StartItem = subitem22;
            link3.EndItem = subitem23;
            link3.LinkType = TasksLinkType.FinishToStart;
            this.radGanttView1.Links.Add(link3);
 
            GanttViewTextViewColumn titleColumn = new GanttViewTextViewColumn("Title");
            GanttViewTextViewColumn startColumn = new GanttViewTextViewColumn("Start");
            GanttViewTextViewColumn endColumn = new GanttViewTextViewColumn("End");
 
            this.radGanttView1.GanttViewElement.Columns.Add(titleColumn);
            this.radGanttView1.GanttViewElement.Columns.Add(startColumn);
            this.radGanttView1.GanttViewElement.Columns.Add(endColumn);
        }
}

I am also sending you a screenshot showing how the RadGanttView looks on my side.

I hope this helps. Should you have further questions please do not hesitate to write back.

Regards,
Hristo
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
GanttView
Asked by
John
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or