radcalendar SpecialDays remove | Winforms

4 posts, 0 answers
  1. RONNY
    RONNY avatar
    7 posts
    Member since:
    Nov 2011

    Posted 23 Oct 2012 Link to this post

    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....:-)
  2. RONNY
    RONNY avatar
    7 posts
    Member since:
    Nov 2011

    Posted 23 Oct 2012 Link to this post

    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???
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Anton
    Admin
    Anton avatar
    167 posts

    Posted 24 Oct 2012 Link to this post

    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.
  5. RONNY
    RONNY avatar
    7 posts
    Member since:
    Nov 2011

    Posted 24 Oct 2012 Link to this post

    Hi Anton,

    perfect, very cool. thank you for your support.

    best recards
    ronny...
Back to Top