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

radcalendar SpecialDays remove | Winforms

3 Answers 123 Views
Calendar, DateTimePicker, TimePicker and Clock
This is a migrated thread and some comments may be shown as answers.
RONNY
Top achievements
Rank 1
RONNY asked on 23 Oct 2012, 09:28 AM
dear,

how can i remove selected specialdays in radcalendar?
i can't find the solution.

and other question is:
When i try with a "for" function remove all Specialdays, then it removes not all specialdays.
(specialday range from 10.10.2012 - 20.10.2012, only remove the following Days: 10,12,14,16,18,20.. between this days it does not remove the specialdays.) 

for (int i = 0; i < radCalendar1.SpecialDays.Count; i++)
            {
 
                radCalendar1.SpecialDays.Remove(radCalendar1.SpecialDays[i]);
 
 
            }

Thank you...


PS: sorry for my english, i hope is enough to find the solution....:-)

3 Answers, 1 is accepted

Sort by
0
RONNY
Top achievements
Rank 1
answered on 23 Oct 2012, 09:41 AM
now i find a solution:

for (int i = 0; i < radCalendar1.SpecialDays.Count; i++)
                {
                    for (int a = 0; a < radCalendar1.SelectedDates.Count; a++)
                    {
                        if (radCalendar1.SpecialDays[i].Date == radCalendar1.SelectedDates[a].Date) radCalendar1.SpecialDays.Remove(radCalendar1.SpecialDays[i]);
                    }
 
                }

but this is very complicated......
mayby there is a better solution???
0
Anton
Telerik team
answered on 24 Oct 2012, 01:39 PM
Hi Ronny,

Thank you for writing.

Your solution is good and needs very small modification because you deleting elements from collection while  iterating over it which is not good pattern. This is the reason why the code snippet from your first post deletes only half days in the range.You can read more about this pattern at this blog article :http://stackoverflow.com/questions/308466/how-to-modify-or-delete-items-from-an-enumerable-collection-while-iterating-thro

Here is the modified version of your code:
for (int i = radCalendar1.SpecialDays.Count -1; i >= 0; i--)
{
    for (int a = 0; a < radCalendar1.SelectedDates.Count; a++)
    {
        if (radCalendar1.SpecialDays[i].Date == radCalendar1.SelectedDates[a].Date)
        {
            radCalendar1.SpecialDays.Remove(radCalendar1.SpecialDays[i]);
            break;
        }
    }
}

Should you have any other questions, I will be glad to assist you.

All the best,
Anton
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
0
RONNY
Top achievements
Rank 1
answered on 24 Oct 2012, 02:10 PM
Hi Anton,

perfect, very cool. thank you for your support.

best recards
ronny...
Tags
Calendar, DateTimePicker, TimePicker and Clock
Asked by
RONNY
Top achievements
Rank 1
Answers by
RONNY
Top achievements
Rank 1
Anton
Telerik team
Share this question
or