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

DateTimePicker: Highlight today's date only

4 Answers 230 Views
DateTimePicker
This is a migrated thread and some comments may be shown as answers.
Ian
Top achievements
Rank 1
Ian asked on 04 Apr 2012, 10:26 AM
Hi,

Is there a way to highlight today's date only and not the selected date on dateTimePicker's calendar?

Many Thanks,

Ian

4 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 09 Apr 2012, 12:16 PM
Hello,

Thank you for contacting us.

You should set CallendarCell Focused property to False in the PopupControl_PopupOpened event.
Please refer to the code below:
public partial class Form1 : Form
    {
        RadDateTimePickerCalendar calendar;
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            calendar = (RadDateTimePickerCalendar)this.radDateTimePicker1.DateTimePickerElement.CurrentBehavior;
            calendar.PopupControl.PopupOpened += new RadPopupOpenedEventHandler(PopupControl_PopupOpened);
        }
         
        void PopupControl_PopupOpened(object sender, EventArgs args)
        {
            RadElementCollection children = calendar.Calendar.CalendarElement.CalendarVisualElement.Children[0].Children[1].Children;
            for (int i = 0; i < children.Count;++i)
            {
                CalendarCellElement cell = (CalendarCellElement)children[i];
                if (cell.Focused)
                {
                    cell.Focused = false;
                }
            }
        }
    }

I hope this helps.

Kind regards,
Peter
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
Ian
Top achievements
Rank 1
answered on 25 Apr 2012, 11:35 AM
Hi Peter,

Thank you for your reply. The code is not working but when I added "cell.Selected = false;" after "cell.Focused= false;", it's working now. Thank you for the answer.

Kind regards,

Ian
0
Ian
Top achievements
Rank 1
answered on 19 Jul 2012, 09:27 AM
Hi,

I found a bug in this solution. While still on the calender, if you move forward a month and then return back to the current month, both the selected date and date today is highlighted. I tried adding the code in radDateTimePicker1.Calendar.MouseClick event but it's still not working. I hope you can help me with this.

Many Thanks,

Ian
0
Peter
Telerik team
answered on 23 Jul 2012, 11:51 AM
Hi Ian,

Thank you for writing back.

To handle all similar cases you should handle Paint event - this is not the best practice and we do not recommend it, but is the only possible solution to achieve the desired behavior.

Please, refer to the code below:
public partial class Form1 : Form
{
    RadDateTimePickerCalendar calendar;
    public Form1()
    {
        InitializeComponent();
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        calendar = (RadDateTimePickerCalendar)this.radDateTimePicker1.DateTimePickerElement.CurrentBehavior;
        calendar.Calendar.Paint += new PaintEventHandler(Calendar_Paint);
         
    }
 
    void Calendar_Paint(object sender, PaintEventArgs e)
    {
        RadElementCollection children = calendar.Calendar.CalendarElement.CalendarVisualElement.Children[0].Children[1].Children;
        for (int i = 0; i < children.Count; ++i)
        {
            CalendarCellElement cell = (CalendarCellElement)children[i];
            if (cell.Focused)
            {
                cell.Focused = false;
                cell.Selected = false;
            }
        }
    }
 
    
}

I hope this helps. All the best,
Peter
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
DateTimePicker
Asked by
Ian
Top achievements
Rank 1
Answers by
Peter
Telerik team
Ian
Top achievements
Rank 1
Share this question
or