public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (final) { _initialValue = Text; } PropertyValue propertyValue = _ownerPropertyEnum.Property.Value; if (Text != propertyValue.DisplayString) { propertyValue.PreviousValue = propertyValue.GetValue(); changed = propertyValue.SetValueFromInPlaceCtrl(Text); PropertyChangedEventArgs pce = new PropertyChangedEventArgs(_ownerPropertyEnum); pce.SelectedIndex = _focusIndex; _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(pce); } Invalidate(); Parent.Invalidate(); return(changed); }
public ValueValidationEventArgs(PropertyEnumerator propEnum, PropertyEnumerator invalidPropEnum, object value, PropertyValue.ValueValidationResult result) : base(propEnum) { _valueValidationResult = result; _valueToValidate = value; _invalidPropEnum = invalidPropEnum; }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (((key == Keys.Return) && !Multiline) || (Multiline && (keyData == Keys.Return))) { if (Parent is IInPlaceControl == false) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { SelectAll(); return(true); } } } else if (key == Keys.Tab) { if (Parent is IInPlaceControl == false) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { SelectAll(); return(true); } } } else if (key == Keys.Escape) { // Restore the old string in the textbox if (_isPassword) { Text = _ownerPropertyEnum.Property.Value.DisplayStringWithoutLook; } else { Text = _ownerPropertyEnum.Property.Value.DisplayString; } if (Parent is IInPlaceControl == false) { CommitChanges(true); } } if (Focused) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { SelectAll(); return(true); } } else if (key == Keys.Tab) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { SelectAll(); return(true); } } else if (key == Keys.Escape) { // Restore the old string in the edit box PropertyValue value = _ownerPropertyEnum.Property.Value; if (value != null) { Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } } if (Focused) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { if (mEdit != null) { _currentValueValidationResult = mEdit.CommitChanges(final); return(_currentValueValidationResult); } _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; return(_currentValueValidationResult); }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { if (_edit != null) { _edit.SelectAll(); return(true); } } } else if (key == Keys.Tab) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { if (_edit != null) { _edit.SelectAll(); } return(true); } } else if (key == Keys.Escape) { // Restore the old string in the textbox Text = _initialValue; CommitChanges(true); } if (ContainsFocus) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (e.Clicks == 2) { Graphics graphics = CreateGraphics(); if (GetButtonRect(graphics).Contains(new Point(e.X, e.Y)) == false) { ScrollValueOnDoubleClick(!(ModifierKeys == Keys.Shift), ScrollValueOnDoubleClickSource.FromInPlaceCtrl, false); } } else { if (RealtimeChange) { PropertyValue.ValueValidationResult changed = CommitChanges(false); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { _edit.Focus(); _edit.SelectAll(); return; } } Graphics graphics = CreateGraphics(); if (GetButtonRect(graphics).Contains(new Point(e.X, e.Y))) { _pushed = true; _mouseOver = true; Capture = true; } graphics.Dispose(); _dontTransferFocus = true; Focus(); _dontTransferFocus = false; Invalidate(false); Update(); } } base.OnMouseDown(e); }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { // SelectAll(); return(true); } } else if (key == Keys.Tab) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { // SelectAll(); return(true); } } else if (key == Keys.Escape) { // Restore the old value in the control Value = _oldValue; CommitChanges(true); } if (Focused) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
public ValueValidationEventArgs(PropertyEnumerator propEnum, PropertyEnumerator invalidPropEnum, object value, PropertyValue.ValueValidationResult result, Exception e) : this(propEnum, invalidPropEnum, value, result) { _exception = e; }
private void HandleUpDownButton(ButtonID buttonId, bool rotate) { string strValue = Text; PropertyUpDownEventArgs args = new PropertyUpDownEventArgs( _ownerPropertyEnum, (buttonId == ButtonID.Up ? PropertyUpDownEventArgs.UpDownButtons.Up : PropertyUpDownEventArgs.UpDownButtons.Down)); args.Value = Text; string oldStr = Text; _ownerPropertyEnum.Property.ParentGrid.OnPropertyUpDown(args); if (Text != args.Value) strValue = args.Value; else { string[] displayedStrings = _ownerPropertyEnum.Property.Value.GetDisplayedValues(); if (displayedStrings.Length > 0) { strValue = Text; if (_ownerPropertyEnum.Property.Value.HasMultipleValues) { int index = -1; if (buttonId == ButtonID.Down) index = displayedStrings.Length - 1; else if (buttonId == ButtonID.Up) index = 0; if (index != -1) strValue = displayedStrings[index]; } else { for (int i = 0; i < displayedStrings.Length; i++) { if (displayedStrings[i] == strValue) { int index = -1; if ((buttonId == ButtonID.Down) && (i > 0)) index = i - 1; else if ((buttonId == ButtonID.Down) && rotate) index = displayedStrings.Length - 1; else if ((buttonId == ButtonID.Up) && (i < displayedStrings.Length - 1)) index = i + 1; else if ((buttonId == ButtonID.Up) && rotate) index = 0; if (index != -1) strValue = displayedStrings[index]; break; } } } } else if (_ownerPropertyEnum.Property.Value.UnderlyingType != typeof(string)) { TypeConverter tc = _ownerPropertyEnum.Property.Value.TypeConverter; PropertyTypeDescriptorContext context = _ownerPropertyEnum.Property.Value.GetTypeDescriptorContext(_ownerPropertyEnum); decimal value; object originalValue; try { if (_ownerPropertyEnum.Property.Value.HasMultipleValues) { DefaultValueAttribute attr = (DefaultValueAttribute)_ownerPropertyEnum.Property.Value.GetAttribute(typeof(DefaultValueAttribute)); if (attr != null) originalValue = attr.Value; else originalValue = 0; value = Convert.ToDecimal(originalValue); } else { originalValue = tc.ConvertFromString(context, _ownerPropertyEnum.Property.Value.CultureInfo, Text); value = Convert.ToDecimal(originalValue); } } catch (Exception e) { _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); return; } if (buttonId == ButtonID.Up) { try { value += Increment; } catch (OverflowException) { } } else if (buttonId == ButtonID.Down) { try { value -= Increment; } catch (OverflowException) { } } CultureInfo culture = _ownerPropertyEnum.Property.Value.CultureInfo; strValue = tc.ConvertToString(context, culture, Convert.ChangeType(value, originalValue.GetType(), culture)); if (strValue == null) strValue = ""; } } if (Text != strValue) { _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyValidatorBase validator = _ownerPropertyEnum.Property.Value.Validator; // Check current value try { object valueToValidate = _ownerPropertyEnum.Property.Value.GetValueToValidate(Text); if (validator != null) { if (!validator.Check(_ownerPropertyEnum.Property.Value.GetValueToValidate(Text), false)) { if (_edit != null) _edit.SelectAll(); _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.ValidatorFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, Text, _currentValueValidationResult)); return; } } } catch (Exception e) { if (_edit != null) _edit.SelectAll(); _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); return; } if (validator != null) { if (!validator.Check(_ownerPropertyEnum.Property.Value.GetValueToValidate(strValue), false)) return; } if (_realtimeChange) CommitChanges(strValue, false); else Text = strValue; } if ((_edit != null) && _edit.Focused) _edit.SelectAll(); else Invalidate(); }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (ReadOnly) { return(changed); } PropertyValue value = _ownerPropertyEnum.Property.Value; // Store the previous value DateTime oldValue = (DateTime)value.GetValue(); // Assign the new value based on the edit content if (Value != oldValue) { // Freeze painting because updating the property may also update other properties in the grid. _ownerPropertyEnum.Property.ParentGrid.BeginUpdate(); _ownerPropertyEnum.Property.Value.PreviousValue = oldValue; PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(Value, out invalidPropertyEnum); if (PropertyValue.IsErrorCode(changed)) { _currentInvalidPropertyEnum = invalidPropertyEnum; } // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Value = (DateTime)value.GetValue(); if (final) { _oldValue = Value; } } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (changed != PropertyValue.ValueValidationResult.Validated) { changed = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, changed)); } } // Notify the properties control if the value has really changed if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, changed)); } _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(new PropertyChangedEventArgs(_ownerPropertyEnum)); } _currentValueValidationResult = changed; // Defreeze painting _ownerPropertyEnum.Property.ParentGrid.EndUpdate(); } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, _currentValueValidationResult)); } } return(changed); }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if ((_edit != null) && _edit.ReadOnly) return changed; PropertyValue value = _ownerPropertyEnum.Property.Value; // Store the previous value object oldValue = null; if (value.HasMultipleValues == false) oldValue = value.GetValue(); object newValue = null; try { if ((value.HasMultipleValues == false) || (Text.Length != 0)) newValue = value.GetActualValue(Text); } catch (Exception e) { _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { Text = value.DisplayString; _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } return _currentValueValidationResult; } if (((newValue != null) && ((oldValue == null) || (newValue.Equals(oldValue) == false))) || ((newValue == null) && (oldValue != null))) { _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(Text, out invalidPropertyEnum); if (PropertyValue.IsErrorCode(changed)) _currentInvalidPropertyEnum = invalidPropertyEnum; _currentValueValidationResult = changed; // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Text = value.DisplayString; if (final) _initialValue = _trackbar.Value; } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (PropertyValue.IsErrorCode(changed)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } _trackbar.Value = (int)newValue; _parentGrid.NotifyPropertyChanged(new PropertyChangedEventArgs(_ownerPropertyEnum)); } Parent.Refresh(); } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } return changed; }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { if ((_trackbar != null) && _trackbar.Focused) { CommitChanges(true); } else { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { if (_edit != null) { _edit.SelectAll(); return(true); } } } } else if (key == Keys.Tab) { PropertyValue.ValueValidationResult changed = CommitChanges(_trackbar.Focused); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { if (_edit != null) { _edit.SelectAll(); } return(true); } if (_edit != null) { bool forward = ((keyData & Keys.Shift) == Keys.None); if (forward && _edit.Focused) { if ((_parentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) || ((_parentGrid.TabKeyNavigationMode & PropertyGrid.TabKeyNavigationModes.TabKeyInSubControls) != 0)) { _trackbar.Focus(); return(true); } } else if (forward && _trackbar.Focused) { if (_realtimeChange == false) { CommitChanges(true); } } else if (!forward && _trackbar.Focused) { _edit.Focus(); _edit.SelectAll(); Invalidate(false); return(true); } } } else if (key == Keys.Escape) { // Restore the old value in the textbox _trackbar.Value = _initialValue; Text = _trackbar.Value.ToString(); CommitChanges(true); } if (ContainsFocus) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if ((_edit != null) && _edit.ReadOnly) { return(changed); } PropertyValue value = _ownerPropertyEnum.Property.Value; // Store the previous value object oldValue = null; if (value.HasMultipleValues == false) { oldValue = value.GetValue(); } object newValue = null; try { if ((value.HasMultipleValues == false) || (Text.Length != 0)) { newValue = value.GetActualValue(Text); } } catch (Exception e) { _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { Text = value.DisplayString; _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } return(_currentValueValidationResult); } if (((newValue != null) && ((oldValue == null) || (newValue.Equals(oldValue) == false))) || ((newValue == null) && (oldValue != null))) { _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(Text, out invalidPropertyEnum); if (PropertyValue.IsErrorCode(changed)) { _currentInvalidPropertyEnum = invalidPropertyEnum; } _currentValueValidationResult = changed; // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Text = value.DisplayString; if (final) { _initialValue = _trackbar.Value; } } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (PropertyValue.IsErrorCode(changed)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } _trackbar.Value = (int)newValue; _parentGrid.NotifyPropertyChanged(new PropertyChangedEventArgs(_ownerPropertyEnum)); } Parent.Refresh(); } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } return(changed); }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (ReadOnly) return changed; PropertyValue value = _ownerPropertyEnum.Property.Value; // Store the previous value DateTime oldValue = (DateTime)value.GetValue(); // Assign the new value based on the edit content if (Value != oldValue) { // Freeze painting because updating the property may also update other properties in the grid. _ownerPropertyEnum.Property.ParentGrid.BeginUpdate(); _ownerPropertyEnum.Property.Value.PreviousValue = oldValue; PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(Value, out invalidPropertyEnum); if (PropertyValue.IsErrorCode(changed)) _currentInvalidPropertyEnum = invalidPropertyEnum; // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Value = (DateTime)value.GetValue(); if (final) _oldValue = Value; } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (changed != PropertyValue.ValueValidationResult.Validated) { changed = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, changed)); } } // Notify the properties control if the value has really changed if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, changed)); } _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(new PropertyChangedEventArgs(_ownerPropertyEnum)); } _currentValueValidationResult = changed; // Defreeze painting _ownerPropertyEnum.Property.ParentGrid.EndUpdate(); } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Value, _currentValueValidationResult)); } } return changed; }
private void HandleUpDownButton(ButtonID buttonId, bool rotate) { string strValue = Text; PropertyUpDownEventArgs args = new PropertyUpDownEventArgs( _ownerPropertyEnum, (buttonId == ButtonID.Up ? PropertyUpDownEventArgs.UpDownButtons.Up : PropertyUpDownEventArgs.UpDownButtons.Down)); args.Value = Text; string oldStr = Text; _ownerPropertyEnum.Property.ParentGrid.OnPropertyUpDown(args); if (Text != args.Value) { strValue = args.Value; } else { string[] displayedStrings = _ownerPropertyEnum.Property.Value.GetDisplayedValues(); if (displayedStrings.Length > 0) { strValue = Text; if (_ownerPropertyEnum.Property.Value.HasMultipleValues) { int index = -1; if (buttonId == ButtonID.Down) { index = displayedStrings.Length - 1; } else if (buttonId == ButtonID.Up) { index = 0; } if (index != -1) { strValue = displayedStrings[index]; } } else { for (int i = 0; i < displayedStrings.Length; i++) { if (displayedStrings[i] == strValue) { int index = -1; if ((buttonId == ButtonID.Down) && (i > 0)) { index = i - 1; } else if ((buttonId == ButtonID.Down) && rotate) { index = displayedStrings.Length - 1; } else if ((buttonId == ButtonID.Up) && (i < displayedStrings.Length - 1)) { index = i + 1; } else if ((buttonId == ButtonID.Up) && rotate) { index = 0; } if (index != -1) { strValue = displayedStrings[index]; } break; } } } } else if (_ownerPropertyEnum.Property.Value.UnderlyingType != typeof(string)) { TypeConverter tc = _ownerPropertyEnum.Property.Value.TypeConverter; PropertyTypeDescriptorContext context = _ownerPropertyEnum.Property.Value.GetTypeDescriptorContext(_ownerPropertyEnum); decimal value; object originalValue; try { if (_ownerPropertyEnum.Property.Value.HasMultipleValues) { DefaultValueAttribute attr = (DefaultValueAttribute)_ownerPropertyEnum.Property.Value.GetAttribute(typeof(DefaultValueAttribute)); if (attr != null) { originalValue = attr.Value; } else { originalValue = 0; } value = Convert.ToDecimal(originalValue); } else { originalValue = tc.ConvertFromString(context, _ownerPropertyEnum.Property.Value.CultureInfo, Text); value = Convert.ToDecimal(originalValue); } } catch (Exception e) { _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); return; } if (buttonId == ButtonID.Up) { try { value += Increment; } catch (OverflowException) { } } else if (buttonId == ButtonID.Down) { try { value -= Increment; } catch (OverflowException) { } } CultureInfo culture = _ownerPropertyEnum.Property.Value.CultureInfo; strValue = tc.ConvertToString(context, culture, Convert.ChangeType(value, originalValue.GetType(), culture)); if (strValue == null) { strValue = ""; } } } if (Text != strValue) { _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyValidatorBase validator = _ownerPropertyEnum.Property.Value.Validator; // Check current value try { object valueToValidate = _ownerPropertyEnum.Property.Value.GetValueToValidate(Text); if (validator != null) { if (!validator.Check(_ownerPropertyEnum.Property.Value.GetValueToValidate(Text), false)) { if (_edit != null) { _edit.SelectAll(); } _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.ValidatorFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, Text, _currentValueValidationResult)); return; } } } catch (Exception e) { if (_edit != null) { _edit.SelectAll(); } _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); return; } if (validator != null) { if (!validator.Check(_ownerPropertyEnum.Property.Value.GetValueToValidate(strValue), false)) { return; } } if (_realtimeChange) { CommitChanges(strValue, false); } else { Text = strValue; } } if ((_edit != null) && _edit.Focused) { _edit.SelectAll(); } else { Invalidate(); } }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { if ((mEdit != null) && mEdit.Focused) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (mOwnerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { mEdit.SelectAll(); return(true); } } } else if (key == Keys.F4) { if ((mEdit != null) && mEdit.Focused) { PropertyValue.ValueValidationResult changed = CommitChanges(false); if (!PropertyValue.IsErrorCode(changed) || (mOwnerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore)) { OnF4(); } else { mEdit.SelectAll(); } } else { OnF4(); } return(true); } else if (key == Keys.Escape) { if ((mEdit != null) && mEdit.Focused) { _pushed = false; PropertyValue value = mOwnerPropertyEnum.Property.Value; Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; mOwnerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, mEdit.CurrentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } } else if (key == Keys.Tab) { if ((mEdit != null) && !ReadOnly) { bool forward = ((keyData & Keys.Shift) == Keys.None); PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (mEdit.Focused) { bool final = !forward && (mOwnerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys); changed = CommitChanges(final); if (PropertyValue.IsErrorCode(changed) && (mOwnerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { mEdit.SelectAll(); return(true); } if (forward) { if ((mOwnerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) || ((mOwnerPropertyEnum.Property.ParentGrid.TabKeyNavigationMode & PropertyGrid.TabKeyNavigationModes.TabKeyInSubControls) != 0)) { // CommitChanges(false); _dontTransferFocus = true; Focus(); Invalidate(false); _dontTransferFocus = false; return(true); } } else { if (mOwnerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) { // CommitChanges(true); Parent.Focus(); return(true); } } } else if (!forward && Focused) { mEdit.Focus(); mEdit.SelectAll(); Invalidate(false); return(true); } } } if (ContainsFocus) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { if ((mEdit != null) && mEdit.Focused) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (mOwnerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { mEdit.SelectAll(); return true; } } } else if (key == Keys.F4) { if ((mEdit != null) && mEdit.Focused) { PropertyValue.ValueValidationResult changed = CommitChanges(false); if (!PropertyValue.IsErrorCode(changed) || (mOwnerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore)) { OnF4(); } else mEdit.SelectAll(); } else OnF4(); return true; } else if (key == Keys.Escape) { if ((mEdit != null) && mEdit.Focused) { _pushed = false; PropertyValue value = mOwnerPropertyEnum.Property.Value; Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; mOwnerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, mEdit.CurrentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } } else if (key == Keys.Tab) { if ((mEdit != null) && !ReadOnly) { bool forward = ((keyData & Keys.Shift) == Keys.None); PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (mEdit.Focused) { bool final = !forward && (mOwnerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys); changed = CommitChanges(final); if (PropertyValue.IsErrorCode(changed) && (mOwnerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { mEdit.SelectAll(); return true; } if (forward) { if ((mOwnerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) || ((mOwnerPropertyEnum.Property.ParentGrid.TabKeyNavigationMode & PropertyGrid.TabKeyNavigationModes.TabKeyInSubControls) != 0)) { // CommitChanges(false); _dontTransferFocus = true; Focus(); Invalidate(false); _dontTransferFocus = false; return true; } } else { if (mOwnerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) { // CommitChanges(true); Parent.Focus(); return true; } } } else if (!forward && Focused) { mEdit.Focus(); mEdit.SelectAll(); Invalidate(false); return true; } } } if (ContainsFocus) return base.ProcessDialogKey(keyData); else return true; }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { _pushed = false; _mouseOver = false; PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { if (_edit != null) { _edit.SelectAll(); return(true); } } } else if (key == Keys.Escape) { _pushed = false; _mouseOver = false; // Restore the old string in the edit box Text = _initialValue; _ownerPropertyEnum.Property.Value.ImageIndex = _oldImageListIndex; CommitChanges(true); } else if ((key == Keys.F4) || ((key == Keys.Down) && ((keyData & Keys.Alt) != Keys.None))) { _pushed = false; _mouseOver = false; if ((_edit != null) && _edit.Focused) { PropertyValue.ValueValidationResult changed = CommitChanges(false); if (!PropertyValue.IsErrorCode(changed) || (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore)) { OnF4(); } else { _edit.SelectAll(); } } else { OnF4(); } return(true); } else if (key == Keys.Tab) { bool forward = ((keyData & Keys.Shift) == Keys.None); bool final = (_edit == null) || (!forward && _edit.Focused); PropertyValue.ValueValidationResult changed = CommitChanges(final); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { if (_edit != null) { _edit.SelectAll(); } return(true); } if (_edit != null) { if (forward && _edit.Focused) { if ((_ownerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) || ((_ownerPropertyEnum.Property.ParentGrid.TabKeyNavigationMode & PropertyGrid.TabKeyNavigationModes.TabKeyInSubControls) != 0)) { // CommitChanges(false); _dontTransferFocus = true; Focus(); Invalidate(false); _dontTransferFocus = false; return(true); } } else if (!forward && _edit.Focused) { if (_ownerPropertyEnum.Property.ParentGrid.NavigationKeyMode == PropertyGrid.NavigationKeyModes.ArrowKeys) { // CommitChanges(true); Parent.Focus(); return(true); } } else if (!forward && Focused) { _edit.Focus(); _edit.SelectAll(); Invalidate(false); return(true); } } } if (ContainsFocus) { return(base.ProcessDialogKey(keyData)); } else { return(true); } }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { if (mEdit != null) { _currentValueValidationResult = mEdit.CommitChanges(final); return _currentValueValidationResult; } _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; return _currentValueValidationResult; }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (ReadOnly) return changed; PropertyValue value = _ownerPropertyEnum.Property.Value; if (value != null) { string oldMask = Mask; Mask = ""; string dislayedText = Text; Mask = oldMask; // Store the previous value object oldValue = null; if (value.HasMultipleValues == false) oldValue = value.GetValue(); // Assign the new value based on the edit content object newValue = null; try { if ((value.HasMultipleValues == false) || (dislayedText.Length != 0)) newValue = value.GetActualValue(dislayedText); } catch (Exception e) { _currentInvalidPropertyEnum = _ownerPropertyEnum; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { Text = value.DisplayString; _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } return _currentValueValidationResult; } if (((newValue != null) && ((oldValue == null) || (newValue.Equals(oldValue) == false))) || ((newValue == null) && (oldValue != null))) { if (MaskCompleted) { // Freeze painting because updating the property may also update other properties in the grid. // If the value is invalid based on the validator, all updated properties will be reverted back to // the previous value and a flicker would happen _ownerPropertyEnum.Property.ParentGrid.BeginUpdate(); _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(dislayedText, out invalidPropertyEnum); if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) _currentInvalidPropertyEnum = invalidPropertyEnum; // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Text = value.DisplayString; } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (PropertyValue.IsErrorCode(changed)) { changed = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } } } else { if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); Text = value.DisplayString; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, value.GetValue(), changed)); } else { changed = PropertyValue.ValueValidationResult.ValidatorFailed; _currentInvalidPropertyEnum = OwnerPropertyEnumerator; PropertyValidatorBase.Message = "Incomplete mask"; OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, changed)); } } // Notify the properties control if the value has really changed if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(new PropertyChangedEventArgs(_ownerPropertyEnum)); } _currentValueValidationResult = changed; // Defreeze painting and repaint _ownerPropertyEnum.Property.ParentGrid.EndUpdate(); } } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } return changed; }
protected override bool ProcessKeyPreview(ref Message m) { if (m.Msg == Win32Calls.WM_KEYDOWN) { Keys key = (Keys)(int)m.WParam; if ((key == Keys.Down) || (key == Keys.Up) || (key == Keys.PageDown) || (key == Keys.PageUp)) { if ((_edit != null) && _edit.Focused) { // Check to see if the current displayed value is valid regarding its TypeConverter object valueToValidate = null; try { valueToValidate = _ownerPropertyEnum.Property.Value.GetValueToValidate(Text); } catch (Exception e) { _edit.SelectAll(); _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); return(true); } int newValue = (int)valueToValidate; if (key == Keys.Down) { newValue -= _trackbar.SmallChange; } else if (key == Keys.Up) { newValue += _trackbar.SmallChange; } else if (key == Keys.PageDown) { newValue -= _trackbar.LargeChange; } else if (key == Keys.PageUp) { newValue += _trackbar.LargeChange; } // Check to see if the current displayed value is valid regarding its validator PropertyValidatorBase validator = _ownerPropertyEnum.Property.Value.Validator; if (validator != null) { bool newValueValid = validator.Check(newValue, false); if (!validator.Check(valueToValidate, false)) { // If the current value is invalid, let's see if the new one will be valid if (newValueValid == false) { _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _edit.SelectAll(); _currentValueValidationResult = PropertyValue.ValueValidationResult.ValidatorFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, valueToValidate, _currentValueValidationResult)); return(true); } } } if (newValue != _trackbar.Value) { if (newValue > _trackbar.Maximum) { newValue = _trackbar.Maximum; } else if (newValue < _trackbar.Minimum) { newValue = _trackbar.Minimum; } _trackbar.Value = newValue; Text = newValue.ToString(); _edit.SelectAll(); if (_realtimeChange) { CommitChanges(false); } return(true); } } } } return(base.ProcessKeyPreview(ref m)); }
protected override bool ProcessKeyPreview(ref Message m) { if (m.Msg == Win32Calls.WM_KEYDOWN) { Keys key = (Keys)(int)m.WParam; if ((key == Keys.Down) || (key == Keys.Up) || (key == Keys.PageDown) || (key == Keys.PageUp)) { if ((_edit != null) && _edit.Focused) { // Check to see if the current displayed value is valid regarding its TypeConverter object valueToValidate = null; try { valueToValidate = _ownerPropertyEnum.Property.Value.GetValueToValidate(Text); } catch (Exception e) { _edit.SelectAll(); _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); return true; } int newValue = (int)valueToValidate; if (key == Keys.Down) newValue -= _trackbar.SmallChange; else if (key == Keys.Up) newValue += _trackbar.SmallChange; else if (key == Keys.PageDown) newValue -= _trackbar.LargeChange; else if (key == Keys.PageUp) newValue += _trackbar.LargeChange; // Check to see if the current displayed value is valid regarding its validator PropertyValidatorBase validator = _ownerPropertyEnum.Property.Value.Validator; if (validator != null) { bool newValueValid = validator.Check(newValue, false); if (!validator.Check(valueToValidate, false)) { // If the current value is invalid, let's see if the new one will be valid if (newValueValid == false) { _currentInvalidPropertyEnum = OwnerPropertyEnumerator; _edit.SelectAll(); _currentValueValidationResult = PropertyValue.ValueValidationResult.ValidatorFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, valueToValidate, _currentValueValidationResult)); return true; } } } if (newValue != _trackbar.Value) { if (newValue > _trackbar.Maximum) newValue = _trackbar.Maximum; else if (newValue < _trackbar.Minimum) newValue = _trackbar.Minimum; _trackbar.Value = newValue; Text = newValue.ToString(); _edit.SelectAll(); if (_realtimeChange) CommitChanges(false); return true; } } } } return base.ProcessKeyPreview(ref m); }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; PropertyValue value = _ownerPropertyEnum.Property.Value; bool compareTextInCommitChanges = value.TypeConverter.CanConvertFrom(typeof(string)); bool textHasChanged = false; if (compareTextInCommitChanges) { textHasChanged = !value.DisplayString.Equals(Text); } object oldValue = null; object newValue = null; bool multipleValues = value.HasMultipleValues; if (!compareTextInCommitChanges || textHasChanged) { // Store the previous value if (!multipleValues) { oldValue = value.GetValue(); } // Assign the new value based on the edit content try { if (!multipleValues || (Text.Length != 0)) { newValue = value.GetActualValue(Text); } } catch (Exception e) { _currentInvalidPropertyEnum = _ownerPropertyEnum; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { Text = value.DisplayString; _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } return(_currentValueValidationResult); } } if ((multipleValues && textHasChanged) || ((newValue != null) && ((oldValue == null) || (newValue.Equals(oldValue) == false))) || ((newValue == null) && (oldValue != null))) { // Freeze painting because updating the property may also update other properties in the grid. _ownerPropertyEnum.Property.ParentGrid.BeginUpdate(); _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(Text, out invalidPropertyEnum); if (PropertyValue.IsErrorCode(changed)) { _currentInvalidPropertyEnum = invalidPropertyEnum; } // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Text = value.DisplayString; if (final) { _initialValue = Text; } } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (PropertyValue.IsErrorCode(changed)) { changed = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } } // Notify the properties control if the value has really changed if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } PropertyChangedEventArgs e = new PropertyChangedEventArgs(_ownerPropertyEnum); e.SelectedIndex = _ownerPropertyEnum.Property.Value.ImageIndex; _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(e); } if (final) { _oldImageListIndex = _ownerPropertyEnum.Property.Value.ImageIndex; } _currentValueValidationResult = changed; // Defreeze painting and redraw _ownerPropertyEnum.Property.ParentGrid.EndUpdate(); } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } if (final) { _oldImageListIndex = _ownerPropertyEnum.Property.Value.ImageIndex; _initialValue = Text; } } return(changed); }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; if (ReadOnly) { return(changed); } PropertyValue value = _ownerPropertyEnum.Property.Value; if (value != null) { string oldMask = Mask; Mask = ""; string dislayedText = Text; Mask = oldMask; // Store the previous value object oldValue = null; if (value.HasMultipleValues == false) { oldValue = value.GetValue(); } // Assign the new value based on the edit content object newValue = null; try { if ((value.HasMultipleValues == false) || (dislayedText.Length != 0)) { newValue = value.GetActualValue(dislayedText); } } catch (Exception e) { _currentInvalidPropertyEnum = _ownerPropertyEnum; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { Text = value.DisplayString; _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } return(_currentValueValidationResult); } if (((newValue != null) && ((oldValue == null) || (newValue.Equals(oldValue) == false))) || ((newValue == null) && (oldValue != null))) { if (MaskCompleted) { // Freeze painting because updating the property may also update other properties in the grid. // If the value is invalid based on the validator, all updated properties will be reverted back to // the previous value and a flicker would happen _ownerPropertyEnum.Property.ParentGrid.BeginUpdate(); _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(dislayedText, out invalidPropertyEnum); if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { _currentInvalidPropertyEnum = invalidPropertyEnum; } // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Text = value.DisplayString; } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (PropertyValue.IsErrorCode(changed)) { changed = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } } } else { if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); Text = value.DisplayString; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, OwnerPropertyEnumerator, value.GetValue(), changed)); } else { changed = PropertyValue.ValueValidationResult.ValidatorFailed; _currentInvalidPropertyEnum = OwnerPropertyEnumerator; PropertyValidatorBase.Message = "Incomplete mask"; OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, changed)); } } // Notify the properties control if the value has really changed if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(new PropertyChangedEventArgs(_ownerPropertyEnum)); } _currentValueValidationResult = changed; // Defreeze painting and repaint _ownerPropertyEnum.Property.ParentGrid.EndUpdate(); } } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } return(changed); }
public virtual PropertyValue.ValueValidationResult CommitChanges(bool final) { PropertyValue.ValueValidationResult changed = PropertyValue.ValueValidationResult.PreviousValueRestored; PropertyValue value = _ownerPropertyEnum.Property.Value; bool compareTextInCommitChanges = value.TypeConverter.CanConvertFrom(typeof(string)); bool textHasChanged = false; if (compareTextInCommitChanges) textHasChanged = !value.DisplayString.Equals(Text); object oldValue = null; object newValue = null; bool multipleValues = value.HasMultipleValues; if (!compareTextInCommitChanges || textHasChanged) { // Store the previous value if (!multipleValues) oldValue = value.GetValue(); // Assign the new value based on the edit content try { if (!multipleValues || (Text.Length != 0)) newValue = value.GetActualValue(Text); } catch (Exception e) { _currentInvalidPropertyEnum = _ownerPropertyEnum; _currentValueValidationResult = PropertyValue.ValueValidationResult.TypeConverterFailed; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, Text, PropertyValue.ValueValidationResult.TypeConverterFailed, e)); if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { Text = value.DisplayString; _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } return _currentValueValidationResult; } } if ((multipleValues && textHasChanged) || ((newValue != null) && ((oldValue == null) || (newValue.Equals(oldValue) == false))) || ((newValue == null) && (oldValue != null))) { // Freeze painting because updating the property may also update other properties in the grid. _ownerPropertyEnum.Property.ParentGrid.BeginUpdate(); _ownerPropertyEnum.Property.Value.PreviousValue = _ownerPropertyEnum.Property.Value.GetValue(); PropertyEnumerator invalidPropertyEnum; changed = value.SetValueFromInPlaceCtrl(Text, out invalidPropertyEnum); if (PropertyValue.IsErrorCode(changed)) _currentInvalidPropertyEnum = invalidPropertyEnum; // Notify the grid if the value is invalid if (changed == PropertyValue.ValueValidationResult.ValidatorFailed) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ValidatorFailed)); } else if (changed == PropertyValue.ValueValidationResult.ExceptionByClient) { OwnerPropertyEnumerator.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, newValue, PropertyValue.ValueValidationResult.ExceptionByClient, value.LastExceptionByClient)); } // We have to update the edit control in case the value was refused or if its string representation // is different from what was typed (changes done by a CultureInfo for example) if ((_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) || (changed == PropertyValue.ValueValidationResult.Validated)) { Text = value.DisplayString; if (final) _initialValue = Text; } // If value is invalid, previous value is restored if ValueNotValidBehaviorMode is set accordingly if (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.IgnoreAndRestore) { if (PropertyValue.IsErrorCode(changed)) { changed = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } } // Notify the properties control if the value has really changed if (changed == PropertyValue.ValueValidationResult.Validated) { if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), changed)); } PropertyChangedEventArgs e = new PropertyChangedEventArgs(_ownerPropertyEnum); e.SelectedIndex = _ownerPropertyEnum.Property.Value.ImageIndex; _ownerPropertyEnum.Property.ParentGrid.NotifyPropertyChanged(e); } if (final) _oldImageListIndex = _ownerPropertyEnum.Property.Value.ImageIndex; _currentValueValidationResult = changed; // Defreeze painting and redraw _ownerPropertyEnum.Property.ParentGrid.EndUpdate(); } else { // Even if the value did not change, we ensure the text displayed is correct. A CultureInfo could // be involved for example that would change a modified text into the old value. Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } if (final) { _oldImageListIndex = _ownerPropertyEnum.Property.Value.ImageIndex; _initialValue = Text; } } return changed; }
protected override bool ProcessDialogKey(Keys keyData) { Keys key = (keyData & Keys.KeyCode); if (key == Keys.Return) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { SelectAll(); return true; } } else if (key == Keys.Tab) { PropertyValue.ValueValidationResult changed = CommitChanges(true); if (PropertyValue.IsErrorCode(changed) && (_ownerPropertyEnum.Property.ParentGrid.ValueNotValidBehaviorMode == PropertyGrid.ValueNotValidBehaviorModes.KeepFocus)) { SelectAll(); return true; } } else if (key == Keys.Escape) { // Restore the old string in the edit box PropertyValue value = _ownerPropertyEnum.Property.Value; if (value != null) { Text = value.DisplayString; if (PropertyValue.IsErrorCode(_currentValueValidationResult)) { _currentValueValidationResult = PropertyValue.ValueValidationResult.PreviousValueRestored; _ownerPropertyEnum.Property.ParentGrid.NotifyValueValidation( new ValueValidationEventArgs(OwnerPropertyEnumerator, _currentInvalidPropertyEnum, value.GetValue(), _currentValueValidationResult)); } } } if (Focused) return base.ProcessDialogKey(keyData); else return true; }