weekend and holiday

8 posts, 1 answers
  1. Frank
    Frank avatar
    8 posts
    Member since:
    Aug 2014

    Posted 11 Dec 2014 Link to this post

    Hello,

    how can I in GanttViewGraphicalViewElement weekends and holidays Show? 

    regards
    frank
  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 15 Dec 2014 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Frank
    Frank avatar
    8 posts
    Member since:
    Aug 2014

    Posted 15 Dec 2014 Link to this post

    Hello Hristo,

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

    regards
    Frank
    .
  5. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 18 Dec 2014 Link to this post

    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.

     
  6. Frank
    Frank avatar
    8 posts
    Member since:
    Aug 2014

    Posted 18 Dec 2014 in reply to Hristo Merdjanov Link to this post

    Hello Hristo,

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

    regards
    Frank

  7. Frank
    Frank avatar
    8 posts
    Member since:
    Aug 2014

    Posted 19 Dec 2014 in reply to Frank Link to this post

    Hello Hristo,

    it works very well.
    Thank you.

    regards
    Frank
  8. John
    John avatar
    1 posts
    Member since:
    Apr 2016

    Posted 20 Oct in reply to Hristo Merdjanov Link to this post

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

    Thanks...

  9. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 21 Oct Link to this post

    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.
Back to Top
UI for WinForms is Visual Studio 2017 Ready