Esempio n. 1
0
        /// <summary>
        /// Inserts an dialog control at the specified index.
        /// </summary>
        /// <param name="index">The location to insert the control.</param>
        /// <param name="control">The item to insert.</param>
        /// <permission cref="System.InvalidOperationException">A control with
        /// the same name already exists in this collection -or-
        /// the control is being hosted by another dialog -or- the associated dialog is
        /// showing and cannot be modified.</permission>
        protected override void InsertItem(int index, T control)
        {
            // Check for duplicates, lack of host,
            // and during-show adds.
            if (Items.Contains(control))
            {
                throw new InvalidOperationException(
                          "Dialog cannot have more than one control with the same name.");
            }
            if (control.HostingDialog != null)
            {
                throw new InvalidOperationException(
                          "Dialog control must be removed from current collections first.");
            }
            if (!hostingDialog.IsCollectionChangeAllowed())
            {
                throw new InvalidOperationException(
                          "Modifying controls collection while dialog is showing is not supported.");
            }
            if (control is CommonFileDialogMenuItem)
            {
                throw new InvalidOperationException(
                          "CommonFileDialogMenuItem controls can only be added to CommonFileDialogMenu controls.");
            }

            // Reparent, add control.
            control.HostingDialog = hostingDialog;
            base.InsertItem(index, control);

            // Notify that we've added a control.
            hostingDialog.ApplyCollectionChanged();
        }
Esempio n. 2
0
        /// <summary>Inserts an dialog control at the specified index.</summary>
        /// <param name="index">The location to insert the control.</param>
        /// <param name="control">The item to insert.</param>
        /// <permission cref="InvalidOperationException">A control with the same name already exists in this collection -or- the control is being hosted by another dialog -or- the associated dialog is showing and cannot be modified.</permission>
        protected override void InsertItem(int index, T control)
        {
            // Check for duplicates, lack of host, and during-show adds.
            if (Items.Contains(control))
            {
                throw new InvalidOperationException(Resources.DialogCollectionCannotHaveDuplicateNames);
            }

            if (control.HostingDialog != null)
            {
                throw new InvalidOperationException(Resources.DialogCollectionControlAlreadyHosted);
            }

            if (!hostingDialog.IsCollectionChangeAllowed())
            {
                throw new InvalidOperationException(Resources.DialogCollectionModifyShowingDialog);
            }

            // Reparent, add control.
            control.HostingDialog = hostingDialog;
            base.InsertItem(index, control);

            // Notify that we've added a control.
            hostingDialog.ApplyCollectionChanged();
        }
        /// <summary>
        /// Inserts an dialog control at the specified index.
        /// </summary>
        /// <param name="index">The location to insert the control.</param>
        /// <param name="control">The item to insert.</param>
        /// <permission cref="System.InvalidOperationException">A control with
        /// the same name already exists in this collection -or-
        /// the control is being hosted by another dialog -or- the associated dialog is
        /// showing and cannot be modified.</permission>
        protected override void InsertItem(int index, T control)
        {
            // Check for duplicates, lack of host,
            // and during-show adds.
            if (Items.Contains(control))
            {
                throw new InvalidOperationException(
                          LocalizedMessages.DialogControlCollectionMoreThanOneControl);
            }
            if (control.HostingDialog != null)
            {
                throw new InvalidOperationException(
                          LocalizedMessages.DialogControlCollectionRemoveControlFirst);
            }
            if (!hostingDialog.IsCollectionChangeAllowed())
            {
                throw new InvalidOperationException(
                          LocalizedMessages.DialogControlCollectionModifyingControls);
            }
            if (control is CommonFileDialogMenuItem)
            {
                throw new InvalidOperationException(
                          LocalizedMessages.DialogControlCollectionMenuItemControlsCannotBeAdded);
            }

            // Reparent, add control.
            control.HostingDialog = hostingDialog;
            base.InsertItem(index, control);

            // Notify that we've added a control.
            hostingDialog.ApplyCollectionChanged();
        }