Declined
Last Updated: 20 Nov 2021 06:26 by ebrahim
ebrahim
Created on: 18 Nov 2021 14:40
Category: UI for WinForms
Type: Bug Report
0
calendar

Hi, when I select a date in the calendar and want to display it in a box, it also displays the base date each time I select a date.

First select the correct date but by selecting the same date show RangMinDate

my code is

private void radCalendar1_SelectionChanged(object sender, EventArgs e)
        {



            label1.Text = radCalendar1.SelectedDate.ToString();

        }

 

 

                        
Attached Files:
2 comments
ebrahim
Posted on: 20 Nov 2021 06:26

thanks mr Dinko

Thank you for your answer. I solved this problem with these codes, but your code is more logical. Thanks too.

if (radCalendar1.SelectedDate != radCalendar1.RangeMinDate)

{

 label1.Text = radCalendar1.SelectedDate.ToString();

}

 

 

ADMIN
Dinko | Tech Support Engineer
Posted on: 19 Nov 2021 10:26

Hi Ebrahim,

Thank you for the provided images.

By default, RadCalendar allows you to select a single date by clicking on it. Then, clicking a selected cell will de-select it. The SelectedDate property does not support null values so when there is no selected date, the default value will be the minimum value. In order to prevent selecting specific dates, you can cancel the RadCalendar.SelectionChanging event. In the event handler, you can check if the NewDates collection is empty. If yes, cancel the event. In the SelectionChanged event handler, you can update the Label.

public RadForm1()
{
    InitializeComponent();
    this.radCalendar1.SelectionChanged += RadCalendar1_SelectionChanged;
    this.radCalendar1.SelectionChanging += RadCalendar1_SelectionChanging; ;
}

private void RadCalendar1_SelectionChanging(object sender, SelectionEventArgs e)
{
    if(e.NewDates.Count== 0)
    {
        e.Cancel = true;
    }
}

private void RadCalendar1_SelectionChanged(object sender, EventArgs e)
{
    label1.Text = radCalendar1.SelectedDate.ToString();
}

Additional information about the calendar's selection is available in the Selecting Dates help article.

I hope this information helps. 

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.