List Property clear, clearing list for all control instances

Movian

Member
Joined
Jul 29, 2013
Messages
8
Location
VA, USA
Programming Experience
3-5
Hey,
I am working with a calendar control
A Professional Calendar/Agenda View That You Will Use - CodeProject

And am running into a problem, I have multiple instances of the control dynamicaly generated in a flowlayoutpanel.

When i have atleast 2 calendars on the form it atempts to clear the Items list that each control generates.

However it ends up clearing the list for EVERY instance of the control and not just the current item. I have checked and nothing is static and the constructor for Calendar creates a new instance of the list.

C#:
_items = new CalendarItemCollection(this);

This means that once it has finished with the first calendar it process the second calendar and all the apointments in the first disapear...

Just trying to figure out how to stop this from happening
 
Indeed but there is a lot of code for different sections, was hoping to get an idea of what to look at so i could post specific sections.

Probably in hind sight i should post how i am generating the calendars. Calendar name is passed to the procedure as a string, i have left out generation of a number of other items such as labels that are not directly related to the calendars.

C#:
//Create and display Calendar
            Calendar MyCal = new Calendar();
            MyCal.Name = Calname;
            MyCal.Height = this.flowLayoutPanel1.Height - 5;
            MyCal.ContextMenuStrip = CalendarMenuStrip;
            MyCal.Font = new Font("Arial", 8, FontStyle.Regular);

            MyCal.ItemDoubleClick += Item_DoubleClick;
            MyCal.MouseDown += RightMouseCal;
            MyCal.ItemCreated += CalendarItemCreated;
            MyCal.ItemDeleted += calendar_ItemDeleted;
            MyCal.LoadItems += CalLoadItems;
            MyCal.ItemMouseHover += ItemHover;

            this.flowLayoutPanel1.Controls.Add(MyCal);

Also i am utelizing the monthview control supplied with the linked project and on a selection change on that control the following code is triggered.

C#:
foreach (Calendar cal in this.flowLayoutPanel1.Controls)
            {
                cal.SetViewRange(monthView1.SelectionStart, monthView1.SelectionEnd);
            }

As mentioned i have tracked down the timing of the disapearance of the appointments in calendar 1 to when the Set_viewEnd event (in the calendar class) is triggered which runs an Items.clear(); which as i mentioned i would have assumed would clear the items only in that instance...

Please note that the following is code from the project and not my own and subject to the GPL terms outlined in the link in my first post.

C#:
        /// <summary>
        /// Gets or sets the end date-time of the current view.
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public DateTime ViewEnd
        {
            get { return _viewEnd; }
            set 
            {
                _viewEnd = value.Date.Add(new TimeSpan(23, 59, 59));
                this.ClearItems();
                this.UpdateDaysAndWeeks();
                this.Renderer.PerformLayout();
                this.Invalidate();
                this.ReloadItems();
            }
        }

I hope this extra information will help to get me pointed in the right direction. This last section of code gets triggered once for each calendar by
C#:
monthView1.SelectionEnd
when its triggered on the first calendar it works great, it clears it and reloads all of the calendar items that need to be displayed. Then when it moves onto calendar 2 (A different instance) when it triggers the This.ClearItems(); I would have assumed it would clear just the second calendar but it clears both leaving the first calendar blank as it only RELOADS the items on that current calendar.

Hoep that makes sense.
 
Back
Top Bottom