Пример #1
0
        internal bool CommitValue(GridEntry ipeCur, object value) {

            Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose,  "PropertyGridView:CommitValue(" + (value==null ? "null" :value.ToString()) + ")");

            int propCount = ipeCur.ChildCount;
            bool capture = Edit.HookMouseDown;
            object originalValue = null;

            try {
                originalValue = ipeCur.PropertyValue;
            }
            catch {
                // if the getter is failing, we still want to let
                // the set happen.
            }

            try {
                try {
                    SetFlag(FlagInPropertySet, true);

                    //if this propentry is enumerable, then once a value is selected from the editor,
                    //we'll want to close the drop down (like true/false).  Otherwise, if we're
                    //working with Anchor for ex., then we should be able to select different values
                    //from the editor, without having it close every time.
                    if (ipeCur != null &&
                        ipeCur.Enumerable) {
                           CloseDropDown();
                    }

                    try {
                        Edit.DisableMouseHook = true;
                        ipeCur.PropertyValue = value;
                    }
                    finally {
                        Edit.DisableMouseHook = false;
                        Edit.HookMouseDown = capture;
                    }
                }
                catch (Exception ex) {
                    SetCommitError(ERROR_THROWN);
                    ShowInvalidMessage(ipeCur.PropertyLabel, value, ex);
                    return false;
                }
            }
            finally {
                SetFlag(FlagInPropertySet, false);
            }

            SetCommitError(ERROR_NONE);

            string text = ipeCur.GetPropertyTextValue();
            if (!String.Equals(text, Edit.Text)) {
                Edit.Text = text;
                Edit.SelectionStart = 0;
                Edit.SelectionLength = 0;
            }
            originalTextValue = text;

            // Update our reset command.
            //
            UpdateResetCommand(ipeCur);

            if (ipeCur.ChildCount != propCount) {
                ClearGridEntryEvents(allGridEntries, 0, -1);
                allGridEntries = null;
                SelectGridEntry(ipeCur, true);
            }

            // in case this guy got disposed...
            if (ipeCur.Disposed) {
                bool editfocused = (edit != null && edit.Focused);
                
                // reselect the row to find the replacement.
                //
                SelectGridEntry(ipeCur, true);
                ipeCur = selectedGridEntry;

                if (editfocused && edit != null) {
                    edit.Focus();
                }
            }

            this.ownerGrid.OnPropertyValueSet(ipeCur, originalValue);

            return true;
        }
 internal bool CommitValue(GridEntry ipeCur, object value)
 {
     int childCount = ipeCur.ChildCount;
     bool hookMouseDown = this.Edit.HookMouseDown;
     object oldValue = null;
     try
     {
         oldValue = ipeCur.PropertyValue;
     }
     catch
     {
     }
     try
     {
         this.SetFlag(0x10, true);
         if ((ipeCur != null) && ipeCur.Enumerable)
         {
             this.CloseDropDown();
         }
         try
         {
             this.Edit.DisableMouseHook = true;
             ipeCur.PropertyValue = value;
         }
         finally
         {
             this.Edit.DisableMouseHook = false;
             this.Edit.HookMouseDown = hookMouseDown;
         }
     }
     catch (Exception exception)
     {
         this.SetCommitError(1);
         this.ShowInvalidMessage(ipeCur.PropertyLabel, value, exception);
         return false;
     }
     finally
     {
         this.SetFlag(0x10, false);
     }
     this.SetCommitError(0);
     string propertyTextValue = ipeCur.GetPropertyTextValue();
     if (!string.Equals(propertyTextValue, this.Edit.Text))
     {
         this.Edit.Text = propertyTextValue;
         this.Edit.SelectionStart = 0;
         this.Edit.SelectionLength = 0;
     }
     this.originalTextValue = propertyTextValue;
     this.UpdateResetCommand(ipeCur);
     if (ipeCur.ChildCount != childCount)
     {
         this.ClearGridEntryEvents(this.allGridEntries, 0, -1);
         this.allGridEntries = null;
         this.SelectGridEntry(ipeCur, true);
     }
     if (ipeCur.Disposed)
     {
         bool flag2 = (this.edit != null) && this.edit.Focused;
         this.SelectGridEntry(ipeCur, true);
         ipeCur = this.selectedGridEntry;
         if (flag2 && (this.edit != null))
         {
             this.edit.Focus();
         }
     }
     this.ownerGrid.OnPropertyValueSet(ipeCur, oldValue);
     return true;
 }