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

weekend and holiday

7 Answers 147 Views
GanttView
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 1
Frank asked on 11 Dec 2014, 07:46 PM
Hello,

how can I in GanttViewGraphicalViewElement weekends and holidays Show? 

regards
frank

7 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 15 Dec 2014, 03:48 PM
Hello Frank,

Thank you for writing.

By default all dates including weekends and holiday are displayed in RadGanttView when the TimelineRange is set to TimeRange.Week or TimeRange.Year

You could change the appearance of the dates corresponding to weekends and holidays if you subscribe to TimelineItemFormatting event and apply the desired styling.

If you would need additional assistance please get back to me with a more detailed information about the desired look and I would be glad to help.

I hope this information is useful. Should you have further questions 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.

 
0
Frank
Top achievements
Rank 1
answered on 15 Dec 2014, 04:38 PM
Hello Hristo,

Thanks, but I meant a vertical display as shown in the attachment.

regards
Frank
.
0
Accepted
Hristo
Telerik team
answered on 18 Dec 2014, 09:15 AM
Hi Frank,

Thank you for writing.

It is possible to create a GanttView as in the picture you attached, however we do not have it out of the box.
You would need to inherit RadGanttViewRadGanttViewElement and GanttViewGraphicalViewElement classes, then override the creation and Theme related methods and at the end implement your own logic for painting the elements at your CustomGanttViewGraphicalViewElement class. Please see the code snippets below with a sample implementation:
public class CustomGanttView : RadGanttView
{
    protected override RadGanttViewElement CreateGanttViewElement()
    {
        return new CustomGanttViewElement();
    }
 
    public override string ThemeClassName
    {
        get { return typeof(RadGanttView).FullName; }
    }
}

public class CustomGanttViewElement : RadGanttViewElement
{
    protected override GanttViewGraphicalViewElement CreateGraphicalViewElement(RadGanttViewElement ganttView)
    {
        return new CustomGanttViewGraphicalViewElement(this);
    }
 
    protected override Type ThemeEffectiveType
    {
        get { return typeof(RadGanttViewElement); }
    }
}

public class CustomGanttViewGraphicalViewElement : GanttViewGraphicalViewElement
{
    private List<DateTime> specialDates = new List<DateTime>();
 
    public List<DateTime> SpecialDates
    {
        get { return specialDates; }
        set { specialDates = value; }
    }
 
    public CustomGanttViewGraphicalViewElement(RadGanttViewElement ganttView)
        : base(ganttView)
    { }
 
    protected override Type ThemeEffectiveType
    {
        get { return typeof(GanttViewGraphicalViewElement); }
    }
 
    //Logic for painting the elements
    protected override void PaintElement(Telerik.WinControls.Paint.IGraphics graphics, float angle, System.Drawing.SizeF scale)
    {
        base.PaintElement(graphics, angle, scale);
 
        Rectangle clipRect = this.Bounds;
        Graphics g = graphics.UnderlayGraphics as Graphics;
 
        g.SetClip(clipRect);
 
        DateTime currentDate = this.TimelineBehavior.AdjustedTimelineStart;
 
        while (currentDate <= this.TimelineBehavior.AdjustedTimelineEnd)
        {
            float x = (float)((currentDate - this.TimelineBehavior.AdjustedTimelineStart).TotalSeconds / this.OnePixelTime.TotalSeconds);
            x -= this.HorizontalScrollBarElement.Value;
            float y = this.GanttViewElement.HeaderHeight;
            float y2 = this.Bounds.Height;
 
            if (currentDate.DayOfWeek == DayOfWeek.Saturday || currentDate.DayOfWeek == DayOfWeek.Sunday)
            {
                graphics.FillRectangle(new RectangleF(x, y, 100f, y2), Color.LightGray);
            }
            else if (this.SpecialDates.Contains(currentDate.Date))
            {
                graphics.FillRectangle(new RectangleF(x, y, 100f, y2), Color.Orange);
            }
            else
            {
                graphics.FillRectangle(new RectangleF(x, y, 100f, y2), Color.White);
            }
 
            graphics.DrawLine(Color.LightBlue, x, y, x, y2);
 
            currentDate = currentDate.AddDays(1);
        }
 
        g.ResetClip();
    }
}

In your form you should also subscribe to the GraphicalViewItemFormatting and TimelineItemFormatting events:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        //this.LoadData();   
        this.radGanttView1.GanttViewElement.GraphicalViewElement.TimelineRange = TimeRange.Month;
        this.Load += Form1_Load;
        this.radGanttView1.GraphicalViewItemFormatting += radGanttView1_GraphicalViewItemFormatting;
        this.radGanttView1.TimelineItemFormatting += radGanttView1_TimelineItemFormatting;
 
        ((CustomGanttViewGraphicalViewElement)this.radGanttView1.GanttViewElement.GraphicalViewElement).SpecialDates.Add(new DateTime(2014, 12, 25));
        ((CustomGanttViewGraphicalViewElement)this.radGanttView1.GanttViewElement.GraphicalViewElement).SpecialDates.Add(new DateTime(2014, 12, 26));
    }
 
    Font font = new Font("Arial",7.5f);
    private void radGanttView1_TimelineItemFormatting(object sender, GanttViewTimelineItemFormattingEventArgs e)
    {
        DateTime date;
        LightVisualElement element;
        for (int i = 0; i < e.ItemElement.Children[1].Children.Count; i++)
        {
            date = e.ItemElement.Data.Start.AddDays(i);
            element = e.ItemElement.Children[1].Children[i] as LightVisualElement;
            if (element!=null)
            {
                element.Text = date.Day + "\n" + date.DayOfWeek.ToString().Substring(0, 2);
                element.Font = font;
            }
        }
    }
 
    void radGanttView1_GraphicalViewItemFormatting(object sender, GanttViewGraphicalViewItemFormattingEventArgs e)
    {
        e.ItemElement.DrawFill = false;
    }
}

I have also attached a screenshot of what the result is on my side. 

Hope this helps. Should you have further questions, 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.

 
0
Frank
Top achievements
Rank 1
answered on 18 Dec 2014, 10:59 AM
Hello Hristo,

thank you.
I will test it in the next few days.

regards
Frank

0
Frank
Top achievements
Rank 1
answered on 19 Dec 2014, 08:53 PM
Hello Hristo,

it works very well.
Thank you.

regards
Frank
​
0
John
Top achievements
Rank 1
answered on 20 Oct 2016, 08:38 PM

You wouldn't happen to have this for a VB solution, I tried Code Converter and am struggling.

Thanks...

0
Hristo
Telerik team
answered on 21 Oct 2016, 06:29 AM
Hi John,

Thank you for writing.

We created a KB resource out of the discussed in this thread solution. The KB article is available here and it has a VB example.

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

Regards,
Hristo Merdjanov
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Tags
GanttView
Asked by
Frank
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Frank
Top achievements
Rank 1
John
Top achievements
Rank 1
Share this question
or