private void Dashboard_ItemCollectionChanged(object sender, NotifyingCollectionChangedEventArgs <DashboardItem> e)
        {
            Dashboard dBoard = sender as Dashboard;

            if (e.AddedItems.Count > 0)
            {
                if (e.AddedItems.Count == 1 && dBoard.Items.Count(i => i.Name == e.AddedItems[0].Name) > 1)
                {
                    AddToLog("Duplicated", e.AddedItems);
                }
                else
                {
                    AddToLog("Added", e.AddedItems);
                }
            }
            if (e.RemovedItems.Count > 0)
            {
                AddToLog("Removed", e.RemovedItems);
            }
        }
Example #2
0
        private void CollectionChangedOrChanging(object sender, NotifyingCollectionChangedEventArgs args)
        {
            const int Items            = 0;
            const int Columns          = 1;
            const int Indices          = 2;
            bool      Changing         = (args is NotifyingCollectionChangingEventArgs);
            int       SourceType       = (sender is NotifyingCollection <int>) ? Indices : (sender is NotifyingCollection <Column>) ? Columns : Items;
            bool      AddEventLogEntry = false;

            switch (SourceType)
            {
            case Items:
                AddEventLogEntry = ((Changing && checkBoxItemsChanging.Checked) || (!Changing && checkBoxItemsChanged.Checked));
                break;

            case Columns:
                AddEventLogEntry = ((Changing && checkBoxColumnsChanging.Checked) || (!Changing && checkBoxColumnsChanged.Checked));
                break;

            case Indices:
                AddEventLogEntry = ((Changing && checkBoxSelectedIndicesChanging.Checked) || (!Changing && checkBoxSelectedIndicesChanged.Checked));
                break;
            }

            if (AddEventLogEntry)
            {
                string Source    = (SourceType == Items) ? "Items" : (SourceType == Columns) ? "Columns" : "SelectedItemIndices";
                string EventType = (Changing) ? "CHANGING" : "CHANGED";
                string Entry     = string.Empty;

                switch (args.Action)
                {
                case NotifyingCollectionChangeAction.Add:
                    Entry = String.Format("{0}[{1}] == ADD {2}[{3}]", Source, EventType, args.NewItem, args.NewItemIndex);
                    break;

                case NotifyingCollectionChangeAction.AddRange:
                    Entry = String.Format("{0}[{1}] == ADD_RANGE", Source, EventType);
                    break;

                case NotifyingCollectionChangeAction.Remove:
                    Entry = String.Format("{0}[{1}] == REMOVE {2}[{3}]", Source, EventType, args.OldItem, args.OldItemIndex);
                    break;

                case NotifyingCollectionChangeAction.RemoveRange:
                    Entry = String.Format("{0}[{1}] == REMOVE_RANGE", Source, EventType);
                    break;

                case NotifyingCollectionChangeAction.Replace:
                    Entry = String.Format("{0}[{1}] == REPLACE {2}[{3}] with {4}[{5}]", Source, EventType, args.OldItem, args.OldItemIndex, args.NewItem, args.NewItemIndex);
                    break;

                case NotifyingCollectionChangeAction.Clear:
                    Entry = String.Format("{0}[{1}] == CLEAR", Source, EventType);
                    break;

                case NotifyingCollectionChangeAction.Sort:
                    Entry = String.Format("{0}[{1}] == SORT", Source, EventType);
                    break;

                default:
                    Entry = String.Format("{0}[{1}] == UNKNOWN", Source, EventType);
                    break;
                }

                listBoxEvents.Items.Add(Entry);
                listBoxEvents.TopIndex = listBoxEvents.Items.Count - 1;
            }


            if (SourceType == Columns)
            {
                numericUpDownColumnIndex.Maximum = dList1.Columns.Count - 1;
            }
            else if (SourceType == Items)
            {
                int NewMax = dList1.Items.Count - 1;
                numericUpDownItemIndex.Maximum       = NewMax;
                numericUpDownItemIndex2.Maximum      = NewMax;
                numericUpDownSelectRangeFrom.Maximum = NewMax;
                numericUpDownSelectRangeTo.Maximum   = NewMax;
            }
        }