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

Winforms Q1 2011 - Selecting a date no longer raised the date selection event

9 Answers 103 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 23 Mar 2011, 04:13 AM
I have just upgraded to the Q1 2011 version of the WinForm Controls and now have a fairly major problem. In previous releases when you programmatically select a date by setting the SelectedDate property in the calendar it triggers the SelectionChanging and SelectionChanged events, this would seem to be the correct behaviour.

The new release does not trigger these events when the ScheduledDate property is set.

To try and get around this I need to at least trigger a refresh event manually so that the ElementRender event will trigger, but there does not seem to be any way to do this, the Refresh and Invalidate methods do not seem to do anything.

Is there anyway to manually trigger a refresh on the calendar?

Peter

9 Answers, 1 is accepted

Sort by
0
Richard Slade
Top achievements
Rank 2
answered on 23 Mar 2011, 12:08 PM
Hello Peter,

Here is an extract from the remarks from the RadCalendar. Note especially the laste section.

Remarks

Use the SelectedDate property to determine the selected date on the >RadCalendar control.

The SelectedDate property and the SelectedDates collection are closely related. When the AllowMultipleSelect property is set to false, a mode that allows only a single date selection, SelectedDate and SelectedDates[0] have the same value and SelectedDates.Count equals 1. When the AllowMultipleSelect property is set to true, mode that allows multiple date selections, SelectedDate and SelectedDates[0] have the same value.

The SelectedDate property is set using a System.DateTime object.

When the user selects a date on the RadCalendar control, the SelectionChanged event is raised. The SelectedDate property is updated to the selected date. The SelectedDates collection is also updated to contain just this date.

Note Both the SelectedDate property and the SelectedDates collection are updated before the SelectionChanged event is raised. You can override the date selection by using the OnSelectionChanged event handler to manually set the SelectedDate property. The SelectionChanged event does not get raised when this property is programmatically set.

However, I've noticed that with this example...
public Form1()
{
    InitializeComponent();
    this.radCalendar1.SelectionChanged += new EventHandler(radCalendar1_SelectionChanged);
}
void radCalendar1_SelectionChanged(object sender, EventArgs e)
{
    MessageBox.Show("RadCalendar Date Changed to " + this.radCalendar1.SelectedDate.ToShortDateString());
}
private void radButton1_Click(object sender, EventArgs e)
{
    this.radCalendar1.SelectedDate = DateTime.Today.AddDays(3);
}

The selection changed event does get raised if the first thing you do is click the button (and it sets the date), but after making some date selections with the mouse, then the button no longer sets the date or (as per the remarks) raises the event.

I'll try and come up with a way to ensure this wil function for you and let you know.
Regards,
Richard


0
Ivan Todorov
Telerik team
answered on 25 Mar 2011, 12:27 PM
Hello Peter,

Have you tried subscribing to the PropertyChanged event? It should look like this:
void radCalendar1_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
    if (e.PropertyName == "SelectedDate")
    {
        // your logic goes here
    }
}

I hope this will help you. If you need further help, do not hesitate to contact me.

Best wishes,
Ivan Todorov
the Telerik team
0
Peter
Top achievements
Rank 1
answered on 26 Mar 2011, 03:56 AM
Ivan

The problem is not that I cannot detect a change in the selected date, I am setting the selected date programmatically (for example a 'today' button), however I use the ElementRender event to highlight various dates on a multi-month calendar (I cannot use SpecialDays as they are too limited).

How can I manually trigger a refresh of the calendar such that the ElementRender event is called? The Refresh and Invalidate methods do not seem to do anything and I have unsuccessfully tried everything I can think of including refreshing parent panels.

Peter
0
Emanuel Varga
Top achievements
Rank 1
answered on 26 Mar 2011, 05:54 PM
Hello Peter,

Have you tried InvalidateCalendar()?

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga

Telerik WinForms MVP
0
Peter
Top achievements
Rank 1
answered on 26 Mar 2011, 10:08 PM
Emanuel

I have tried InvalidateCalendar() and every other method I can find, there does not appear to be any functioning mechanism to force a redraw in the calendar.

I am afraid that it looks like I will have to abandon the Telerik Calendar control and go back to my previous Calendar solution as I cannot afford to waste any more time on this problem.

Peter

0
Richard Slade
Top achievements
Rank 2
answered on 27 Mar 2011, 01:15 AM
Hi Peter,

In my opinion, I agree that this is an issue that you cannot select a date programatically (for exmaple by clicking a button) and then see the calendar update it's view accordingly. Please could you open a support ticket with a small project that demonstrates the issue and reference this thread so that Telerik are able to keep a trail of any discussion. If you would like me to do that for you and feed back and reply, just let me know.

Thanks
Richard
0
Peter
Top achievements
Rank 1
answered on 28 Mar 2011, 01:16 AM
Richard

I did a bit more work on trying to get the control to work, however I thik it is probably beyond redemption, after a bit more work I managed to find a way of forcing a redraw of the control, I will not share it here because it is ugly and requires changing the control from multiview to singleview and back again. Thats when I found out that setting the SelectedDate programatically has no effect on the control anyway and does not set the selecteddate to anything so the following line:

this.RadCalendar1.SelectedDate = DateTime.Today;

has no effect on the selected date, although setting the FocusedDate works. Because of the number of bugs with SelectedDate in the previous version of the control I had given up using it and was using FocusedDate instead which is why I did not notice it prior to this.

Please feel free to go ahead and report the various problems with the RadCalendar, I had a deadline to meet so I had to abandon the RadCalendar and go with a more reliable solution.

Peter
0
Richard Slade
Top achievements
Rank 2
answered on 28 Mar 2011, 11:40 AM
Hello again Peter,

I have noticed that this is actually already reported in the Public Issue Tracking System here. The issue is when AllowMultipleSelect = false. you can vote for the issue to be fixed by visiting the link.
I hope that this helps. If so, please remember to mark as answer and if you need further help, please let me know
Thanks
Richard
0
Ivan Todorov
Telerik team
answered on 30 Mar 2011, 03:57 PM
Hi Peter,

I confirm the issue with setting the SelectedDate programmatically has appeared in the latest release. It will be addressed in the next SP. For the time being, I can provide you with the following workaround: before setting the SelectedDate property, just clear the SelectedDates collection:

radCalendar1.SelectedDates.Clear();
radCalendar1.SelectedDate = DateTime.Today.AddDays(3);

Your Telerik points have been updated for bringing this issue to our attention.

I understand your position. Still, if you decide, you can always open a support ticket when you are experiencing difficulties with our controls and we will do our best to assist you.

I hope this helps.

Regards,
Ivan Todorov
the Telerik team
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
Peter
Top achievements
Rank 1
Answers by
Richard Slade
Top achievements
Rank 2
Ivan Todorov
Telerik team
Peter
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Share this question
or