Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
CellEditor.cs
Package: DXperience9.3.2.rar [view]
Upload User: linjidu
Upload Date: 2021-04-29
Package Size: 49798k
Code Size: 31k
Category:
CSharp
Development Platform:
C#
- #region Copyright (c) 2000-2009 Developer Express Inc.
- /*
- {*******************************************************************}
- { }
- { Developer Express .NET Component Library }
- { DXGrid }
- { }
- { Copyright (c) 2000-2009 Developer Express Inc. }
- { ALL RIGHTS RESERVED }
- { }
- { The entire contents of this file is protected by U.S. and }
- { International Copyright Laws. Unauthorized reproduction, }
- { reverse-engineering, and distribution of all or any portion of }
- { the code contained in this file is strictly prohibited and may }
- { result in severe civil and criminal penalties and will be }
- { prosecuted to the maximum extent possible under the law. }
- { }
- { RESTRICTIONS }
- { }
- { THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES }
- { ARE CONFIDENTIAL AND PROPRIETARY TRADE }
- { SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS }
- { LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET }
- { CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
- { }
- { THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED }
- { FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE }
- { COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE }
- { AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT }
- { AND PERMISSION FROM DEVELOPER EXPRESS INC. }
- { }
- { CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON }
- { ADDITIONAL RESTRICTIONS. }
- { }
- {*******************************************************************}
- */
- #endregion Copyright (c) 2000-2009 Developer Express Inc.
- using System.Windows;
- using DevExpress.Wpf.Core;
- using System.Windows.Media;
- using System.ComponentModel;
- using System.Windows.Input;
- using System.Globalization;
- using System.Windows.Controls;
- using System;
- using DevExpress.Wpf.Editors;
- using System.Windows.Data;
- using DevExpress.Wpf.Core.Native;
- using DevExpress.XtraEditors.DXErrorProvider;
- using DevExpress.Wpf.Editors.Helpers;
- using DevExpress.Wpf.Editors.Settings;
- using DevExpress.Wpf.Editors.Validation;
- using DevExpress.Wpf.Utils.Themes;
- using DevExpress.Wpf.Data;
- using System.Collections.Generic;
- using System.Collections;
- using DevExpress.Wpf.Editors.Native;
- namespace DevExpress.Wpf.Grid {
- public abstract class CellEditorBase : DataContentPresenter, IWeakEventListener, IDisplayTextProvider {
- protected enum BaseEditSourceType { EditSettings, CellTemplate }
- const int EscCode = 27;
- public static readonly DependencyProperty FieldNameProperty;
- public static readonly DependencyProperty ColumnProperty;
- static CellEditorBase() {
- FocusableProperty.OverrideMetadata(typeof(CellEditorBase), new FrameworkPropertyMetadata(true));
- FieldNameProperty = DependencyProperty.Register("FieldName", typeof(string), typeof(CellEditorBase), new FrameworkPropertyMetadata(null, (d, e) => ((CellEditorBase)d).OnFieldNameChanged()));
- ColumnProperty = DependencyProperty.Register("Column", typeof(GridColumn), typeof(CellEditorBase), new FrameworkPropertyMetadata(null, (d, e) => ((CellEditorBase)d).OnColumnChanged((GridColumn)e.OldValue)));
- TableView.IsFocusedCellProperty.OverrideMetadata(typeof(CellEditorBase), new FrameworkPropertyMetadata((d, e) => ((CellEditorBase)d).OnIsFocusedCellChanged()));
- GridColumn.NavigationIndexProperty.AddOwner(typeof(CellEditorBase));
- }
- static bool GetIsEditorButtonVisible(EditorButtonShowMode editorShowMode, bool isFocusedCell, bool isFocusedRow, bool isEditorVisible) {
- switch(editorShowMode) {
- case EditorButtonShowMode.ShowAlways:
- return true;
- case EditorButtonShowMode.ShowOnlyInEditor:
- return isEditorVisible;
- case EditorButtonShowMode.ShowForFocusedRow:
- return isFocusedRow;
- default:
- return isFocusedCell;
- }
- }
- public string FieldName {
- get { return (string)GetValue(FieldNameProperty); }
- set { SetValue(FieldNameProperty, value); }
- }
- public GridColumn Column {
- get { return (GridColumn)GetValue(ColumnProperty); }
- set { SetValue(ColumnProperty, value); }
- }
- public int NavigationIndex {
- get { return (int)GetValue(GridColumn.NavigationIndexProperty); }
- set { SetValue(GridColumn.NavigationIndexProperty, value); }
- }
- public bool IsEditorVisible { get { return Edit.EditMode == EditMode.InplaceActive; } }
- internal void LockEditorFocus() { Edit.LockEditorFocus(); }
- internal void UnlockEditorFocus() { Edit.UnlockEditorFocus(); }
- protected BaseEditSourceType EditorSourceType { get; private set; }
- protected BaseEdit editCore;
- IBaseEdit editWrapper;
- EditGridCellData cellData;
- internal virtual bool IsInTree { get { return View != null; } }
- protected virtual bool IsRowFocused { get { return RowHandle == View.FocusedRowHandle; } }
- protected bool HasAccessToCellValue { get { return IsInTree && Column != null; } }
- internal object EditableValue { get { return Edit.EditValue; } set { Edit.EditValue = value; } }
- internal GridViewBase View { get { return GridControl.GetActiveView(this); } }
- protected GridControl Grid { get { return View.Grid; } }
- protected abstract int RowHandle { get; }
- protected abstract bool IsReadOnly { get; }
- internal RowData RowData { get { return RowData.GetRowData(this); } }
- protected abstract bool OverrideCellTemplate { get; }
- protected string FieldNameCore { get { return Column.FieldName; } }
- protected IBaseEdit Edit { get { return editWrapper != null ? editWrapper : FakeBaseEdit.Instance; } }
- protected virtual EditGridCellData CellData {
- get { return cellData; }
- set {
- if(CellData == value)
- return;
- if(CellData != null) {
- CellData.ContentChanged -= new EventHandler(OnInnerContentChanged);
- if(CellData.CellEditor == this)
- CellData.CellEditor = null;
- }
- cellData = value;
- if(CellData != null) {
- CellData.ContentChanged += new EventHandler(OnInnerContentChanged);
- CellData.CellEditor = this;
- }
- }
- }
- protected internal bool IsChildElement(IInputElement element) {
- return Edit.IsChildElement(element);
- }
- void SetEdit(BaseEdit value) {
- if(editCore == value)
- return;
- if(editCore != null) {
- editCore.EditorActivated -= new RoutedEventHandler(OnEditorActivated);
- editCore.PreviewLostKeyboardFocus -= new KeyboardFocusChangedEventHandler(OnEditorPreviewLostKeyboardFocus);
- }
- editCore = value;
- editWrapper = editCore != null ? new BaseEditWrapper(editCore) : null;
- if(editCore != null) {
- editCore.EditorActivated += new RoutedEventHandler(OnEditorActivated);
- editCore.PreviewLostKeyboardFocus += new KeyboardFocusChangedEventHandler(OnEditorPreviewLostKeyboardFocus);
- }
- }
- bool IsCellFocused {
- get {
- return TableView.GetIsFocusedCell(this);
- }
- }
- protected virtual void OnColumnContentChanged(object sender, ColumnContentChangedEventArgs e) {
- if(e.Property == GridColumn.DisplayTemplateProperty) {
- UpdateDisplayTemplate();
- return;
- }
- if(e.Property == null)
- UpdateContent();
- }
- internal Locker SetKeyboardFocusToEditorLocker { get { return View.SetKeyboardFocusToEditorLocker; } }
- protected CellEditorBase() {
- }
- protected virtual void UpdateEditContext() {
- if(HasAccessToCellValue)
- EditableValue = Grid.GetCellValue(RowHandle, FieldNameCore);
- }
- internal void ActivateOnLeftMouseButton(MouseButtonEventArgs e, bool isMouseDown) {
- if(IsCellFocused) {
- if(!Edit.IsEditorActive) {
- ShowEditorIfNotVisible(!isMouseDown);
- if(IsEditorVisible && isMouseDown) {
- View.DataPresenter.EnqueueImmediateAction(new RaisePostponedMouseEventAction(this, e));
- e.Handled = true;
- }
- }
- }
- }
- protected override void OnPreviewTextInput(TextCompositionEventArgs e) {
- base.OnPreviewTextInput(e);
- if(string.IsNullOrEmpty(e.Text) || !string.IsNullOrEmpty(e.ControlText) || !string.IsNullOrEmpty(e.SystemText) || (int)e.Text[0] == EscCode)
- return;
- if(!IsEditorVisible)
- ShowEditorAndSelectAll();
- if(IsEditorVisible && !Edit.IsEditorActive) {
- View.DataPresenter.EnqueueImmediateAction(new RaisePostponedTextInputEventAction(this, e));
- e.Handled = true;
- }
- }
- internal void ProcessActivatingKey(KeyEventArgs e) {
- Edit.ProcessActivatingKey(e);
- }
- protected override void OnPreviewKeyDown(KeyEventArgs e) {
- base.OnPreviewKeyDown(e);
- if(!IsEditorVisible && Edit.IsActivatingKey(e)) {
- ShowEditorAndSelectAll();
- if(IsEditorVisible) {
- View.DataPresenter.EnqueueImmediateAction(new ProcessActivatingKeyAction(this, e));
- e.Handled = true;
- } else {
- RaiseKeyDownEvent(e);
- }
- return;
- }
- if(!Edit.NeedsKey(e)) {
- if(e.Key == Key.Enter) {
- if(IsEditorVisible) {
- CommitEditor();
- View.EditorWasClosed = true;
- } else {
- ShowEditorAndSelectAll();
- }
- e.Handled = true;
- }
- if(e.Key == Key.F2) {
- if(!IsEditorVisible) {
- ShowEditorAndSelectAll();
- e.Handled = true;
- }
- }
- if(e.Key == Key.Escape) {
- if(IsEditorVisible) {
- CancelEditInVisibleEditor();
- e.Handled = true;
- }
- else
- CancelRowEdit();
- }
- if(!e.Handled) {
- RaiseKeyDownEvent(e);
- }
- }
- }
- internal void CancelEditInVisibleEditor() {
- if(!IsEditorVisible)
- return;
- RestoreValidationError();
- HideEditor();
- View.EditorWasClosed = true;
- }
- protected virtual void CancelRowEdit() {
- }
- protected virtual void RestoreValidationError() {
- }
- void RaiseKeyDownEvent(KeyEventArgs e) {
- e.Handled = true;
- View.ProcessKeyDown(e);
- }
- internal void ShowEditor() {
- ShowEditor(false);
- }
- internal void ShowEditor(bool selectAll) {
- if(!CanShowEditor())
- return;
- if(!IsEditorVisible) {
- UpdateEditTemplate();
- Edit.IsReadOnly = IsReadOnly;
- Edit.EditMode = EditMode.InplaceActive;
- View.SetActiveEditor(editCore);
- Edit.SetKeyboardFocus();
- UpdateEditContext();
- Edit.EditValueChanged += new EditValueChangedEventHandler(OnEditValueChanged);
- }
- View.OnShowEditor();
- View.EditorWasClosed = false;
- UpdateEditorButtonVisibility();
- Edit.IsValueChanged = false;
- if(selectAll)
- View.DataPresenter.EnqueueImmediateAction(new SelectAllAction(this));
- }
- void OnEditValueChanged(object sender, EditValueChangedEventArgs e) {
- View.RaiseCellValueChanging(new CellValueChangedEventArgs(View, RowHandle, Column, Edit.EditValue, e.OldValue) { RoutedEvent = TableView.CellValueChangingEvent });
- OnEditValueChanged();
- }
- protected virtual void OnEditValueChanged() {
- }
- internal void ShowEditorIfNotVisible(bool selectAll) {
- if(!IsEditorVisible)
- ShowEditor(selectAll);
- }
- internal void ShowEditorAndSelectAll() {
- ShowEditor(true);
- }
- protected internal virtual bool CanShowEditor() {
- return IsCellFocused && RaiseShowingEditor();
- }
- bool RaiseShowingEditor() {
- ShowingEditorEventArgs e = new ShowingEditorEventArgs(View, RowHandle, Column);
- View.RaiseShowingEditor(e);
- return !e.Cancel;
- }
- internal void CommitEditor() {
- if(!IsEditorVisible)
- return;
- if(PostEditor())
- HideEditor();
- }
- protected internal virtual bool PostEditor() {
- return true;
- }
- protected internal virtual void ValidateEditor() {
- }
- internal void HideEditor() {
- if(IsEditorVisible) {
- Edit.EditMode = EditMode.InplaceInactive;
- Edit.EditValueChanged -= new EditValueChangedEventHandler(OnEditValueChanged);
- if(View.ActiveEditor == editCore)
- View.SetActiveEditor(null);
- OnHiddenEditor();
- }
- }
- protected virtual void OnHiddenEditor() {
- UpdateEditorButtonVisibility();
- View.OnHideEditor();
- View.RaiseHiddenEditor(new EditorEventArgs(View, RowHandle, Column, editCore) { RoutedEvent = TableView.HiddenEditorEvent });
- }
- void OnIsFocusedCellChanged() {
- if(IsCellFocused) {
- if(View.IsKeyboardFocusWithin) {
- Edit.SetKeyboardFocus();
- if(!IsKeyboardFocusWithin)
- Keyboard.Focus(this);
- }
- UpdateEditorToShow();
- }
- else {
- if(IsEditorVisible)
- CommitEditor();
- if(IsInTree) {
- if(IsKeyboardFocusWithin)
- Keyboard.Focus(View);
- ClearViewCurrentCellEditor(View);
- }
- }
- UpdateEditorButtonVisibility();
- }
- protected void ClearViewCurrentCellEditor(GridViewBase view) {
- if(view.CurrentCellEditor == this)
- view.CurrentCellEditor = null;
- }
- void UpdateEditorToShow() {
- if(IsCellFocused) {
- View.CurrentCellEditor = this;
- }
- }
- #if DEBUGTEST
- internal int InnerContentChangedFireCount { get; set; }
- #endif
- protected override void OnInnerContentChangedCore() {
- base.OnInnerContentChangedCore();
- #if DEBUGTEST
- InnerContentChangedFireCount++;
- #endif
- if(!IsInTree)
- return;
- UpdateContent();
- UpdateEditorButtonVisibility();
- UpdateValidationError();
- }
- void OnColumnChanged(GridColumn oldValue) {
- UpdateData();
- if(oldValue != null) {
- ContentChangedEventManager.RemoveListener(oldValue, this);
- }
- if(Column != null) {
- ContentChangedEventManager.AddListener(Column, this);
- UpdateContent();
- }
- }
- void OnFieldNameChanged() {
- if(Column == null && FieldName != null)
- Column = View.Columns[FieldName];
- }
- protected virtual void UpdateData() {
- if(HasAccessToCellValue) {
- CellData = (EditGridCellData)RowData.GetCellDataByColumn(Column);
- } else {
- CellData = null;
- Content = null;
- }
- }
- protected void UpdateContent() {
- if(!IsInTree)
- return;
- if(Column.ActualCellTemplateSelector.SelectTemplate(CellData, this) == null || OverrideCellTemplate) {
- if(editCore == null || !IsProperEditorSettings()) {
- BaseEdit newEdit = CreateEditor(Column.ActualEditSettings);
- newEdit.DataContext = CellData;
- InitializeBaseEdit(newEdit, BaseEditSourceType.EditSettings);
- ContentTemplateSelector = null;
- Content = newEdit;
- } else {
- if(!object.ReferenceEquals(BaseEditHelper.GetEditSettings(editCore), Column.ActualEditSettings)) {
- Column.ActualEditSettings.ApplyToEdit(editCore, true, Column);
- editCore.DataContext = CellData;
- }
- }
- } else {
- Content = CellData;
- ContentTemplateSelector = Column.ActualCellTemplateSelector;
- if(EditorSourceType == BaseEditSourceType.EditSettings)
- SetEdit(null);
- }
- }
- protected virtual bool IsProperEditorSettings() {
- return object.ReferenceEquals(BaseEditHelper.GetEditSettings(editCore), Column.ActualEditSettings);
- }
- protected virtual BaseEdit CreateEditor(BaseEditSettings settings){
- return settings.CreateEditor(Column);
- }
- public override void OnApplyTemplate() {
- base.OnApplyTemplate();
- BaseEdit editFromTemplate = GetTemplateChild("PART_Editor") as BaseEdit;
- if(editFromTemplate != null)
- InitializeBaseEdit(editFromTemplate, BaseEditSourceType.CellTemplate);
- }
- void InitializeBaseEdit(BaseEdit newEdit, BaseEditSourceType newBaseEditSourceType) {
- this.EditorSourceType = newBaseEditSourceType;
- newEdit.EditMode = EditMode.InplaceInactive;
- UpdateEditValue(newEdit);
- SetEdit(newEdit);
- UpdateEditorButtonVisibility();
- UpdateDisplayTemplate();
- UpdateValidationError();
- SetDisplayTextProvider(newEdit);
- }
- protected virtual void SetDisplayTextProvider(BaseEdit newEdit) {
- BaseEditHelper.SetDisplayTextProvider(newEdit, this);
- }
- protected virtual void UpdateEditValue(BaseEdit editor) {
- editor.SetBinding(BaseEdit.EditValueProperty, new Binding(GridCellData.ValueProperty.Name) { Mode = BindingMode.TwoWay, UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged });
- }
- protected override HitTestResult HitTestCore(PointHitTestParameters hitTestParameters) {
- HitTestResult result = base.HitTestCore(hitTestParameters);
- return result == null ? new PointHitTestResult(this, hitTestParameters.HitPoint) : result;
- }
- void OnEditorPreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) {
- if(!IsInTree || Edit.IsChildElement(e.NewFocus)) {
- return;
- }
- if(IsEditorVisible && Edit.IsEditorActive) {
- SetKeyboardFocusToEditorLocker.DoLockedAction(() => CommitEditor());
- }
- if(View.HasCellEditorError)
- e.Handled = true;
- }
- void OnEditorActivated(object sender, RoutedEventArgs e) {
- View.RaiseShownEditor(new EditorEventArgs(View, RowHandle, Column, editCore));
- }
- internal void UpdateEditorButtonVisibility() {
- if(!IsInTree)
- return;
- Edit.IsEditButtonsVisible = GetIsEditorButtonVisible(View.EditorButtonShowMode, TableView.GetIsFocusedCell(this), IsRowFocused, IsEditorVisible);
- }
- protected virtual void UpdateEditTemplate() {
- Edit.SetEditTemplate(Column.EditTemplate);
- }
- protected virtual void UpdateDisplayTemplate() {
- Edit.SetDisplayTemplate(Column.DisplayTemplate);
- }
- protected virtual void UpdateValidationError() {
- }
- internal void SelectAll() {
- Edit.SelectAll();
- }
- #region IWeakEventListener Members
- bool IWeakEventListener.ReceiveWeakEvent(Type managerType, object sender, EventArgs e) {
- if(managerType == typeof(ContentChangedEventManager)) {
- OnColumnContentChanged(sender, (ColumnContentChangedEventArgs)e);
- return true;
- }
- return false;
- }
- #endregion
- #region IDisplayTextProvider Members
- string IDisplayTextProvider.GetDisplayText(string originalDisplayText) {
- if(!IsInTree)
- return originalDisplayText;
- return View.Grid.RaiseCustomDisplayText(RowHandle, Column, Edit.EditValue, originalDisplayText);
- }
- #endregion
- }
- public class CellEditor : CellEditorBase {
- static CellEditor() {
- DefaultStyleKeyProperty.OverrideMetadata(typeof(CellEditor), new FrameworkPropertyMetadata(typeof(CellEditor)));
- RowData.RowDataProperty.OverrideMetadata(typeof(CellEditor), new FrameworkPropertyMetadata((d, e) => ((CellEditor)d).OnRowDataChanged((RowData)e.OldValue)));
- }
- public CellEditor() {
- }
- internal override bool IsInTree { get { return base.IsInTree && RowData != null; } }
- protected override int RowHandle { get { return RowData.RowHandle != null ? RowData.RowHandle.Value : GridControl.InvalidRowHandle; } }
- protected override bool IsReadOnly { get { return Column.ReadOnly || View.DataProvider.IsColumnReadonly(Column.FieldName); } }
- protected override bool OverrideCellTemplate { get { return false; } }
- protected internal override bool CanShowEditor() {
- return Column.GetAllowEditing() && base.CanShowEditor();
- }
- protected internal override bool PostEditor() {
- if(Edit.IsValueChanged) {
- ValidateEditor();
- if(View.HasCellEditorError) {
- return false;
- }
- if(HasAccessToCellValue) {
- try {
- Grid.SetCellValue(RowData.RowHandle.Value, FieldNameCore, EditableValue);
- } catch(Exception e) {
- ShowError(new GridCellValidationError(e.Message, e, ErrorType.Default, RowData.RowHandle.Value, Column));
- return false;
- }
- RowData.UpdateData();
- }
- }
- return true;
- }
- protected internal override void ValidateEditor() {
- if(IsEditorVisible) {
- Edit.FlushPendingEditActions();
- ShowError(GetValidationError());
- }
- }
- protected override void OnHiddenEditor() {
- CellData.UpdateValue();
- base.OnHiddenEditor();
- }
- protected override void CancelRowEdit() {
- View.DataProvider.CancelCurrentRowEdit();
- View.OnCancelRowEdit();
- View.Grid.SetRowStateError(RowData.RowHandle.Value, null);
- }
- protected override void OnEditValueChanged() {
- base.OnEditValueChanged();
- View.OnFocusedRowCellModified();
- }
- void ShowError(GridCellValidationError validationError) {
- SetValidationError(null);
- if(validationError != null)
- SetValidationError(validationError);
- else
- RestoreValidationError();
- }
- GridCellValidationError GetValidationError() {
- ValidationResult validationResult;
- Exception exception = null;
- if(!Edit.DoValidate())
- return new GridCellValidationError("Invalid Value", null, ErrorType.Default, RowData.RowHandle.Value, Column);
- GridCellValidationEventArgs eventArgs = new GridCellValidationEventArgs(BaseEdit.ValidateEvent, this, EditableValue, CultureInfo.CurrentCulture, RowData.RowHandle.Value, View, Column);
- try {
- Column.OnValidation(eventArgs);
- validationResult = new ValidationResult(eventArgs.IsValid, eventArgs.ErrorContent);
- } catch(Exception e) {
- exception = e;
- validationResult = new ValidationResult(false, e.Message);
- }
- return validationResult.IsValid ? null : new GridCellValidationError(
- validationResult.ErrorContent,
- exception,
- eventArgs.ErrorType == ErrorType.None ? ErrorType.Default : eventArgs.ErrorType,
- RowData.RowHandle.Value,
- Column
- );
- }
- void SetValidationError(GridCellValidationError validationError) {
- View.ValidationError = validationError;
- BaseEditHelper.SetValidationError(RowData, validationError);
- BaseEditHelper.SetValidationError(CellData, validationError);
- Edit.SetValidationError(validationError);
- RowData.UpdateIndicatorState();
- }
- protected override void RestoreValidationError() {
- View.ValidationError = null;
- RowData.UpdateDataErrors();
- }
- protected override void UpdateValidationError() {
- Edit.SetValidationError(BaseEdit.GetValidationError(CellData));
- }
- void OnRowDataChanged(RowData oldValue) {
- UpdateData();
- if(!IsInTree)
- if(oldValue != null)
- ClearViewCurrentCellEditor(oldValue.View);
- }
- protected override bool IsProperEditorSettings() {
- return EditSettingsComparer.IsCompatibleEditSettings(editCore, Column.ActualEditSettings);
- }
- protected override void OnContentInvalidated() {
- base.OnContentInvalidated();
- if(editCore != null && EditorSourceType == BaseEditSourceType.CellTemplate)
- editCore.ClearValue(BaseEdit.EditValueProperty);
- }
- }
- public class FilterRowCellEditor : CellEditorBase {
- public FilterRowCellEditor() : base() {
- TableView.SetRowHandle(this, new RowHandle(RowHandle));
- }
- protected override int RowHandle { get { return GridControl.AutoFilterRowHandle; } }
- protected override bool IsReadOnly { get { return !Column.AllowAutoFilter; } }
- protected override bool OverrideCellTemplate { get { return true; } }
- protected override void UpdateEditContext() {
- }
- protected override void UpdateDisplayTemplate() {
- }
- protected override void UpdateEditTemplate() {
- }
- protected override BaseEdit CreateEditor(BaseEditSettings settings) {
- CheckEditSettings checkEditSettings = settings as CheckEditSettings;
- if(checkEditSettings != null) {
- CheckEdit checkEdit = (CheckEdit)checkEditSettings.CreateEditor(false, EmptyDefaultEditorViewInfo.Instance);
- checkEdit.IsThreeState = true;
- checkEdit.IsChecked = null;
- return checkEdit;
- }
- if(Column.ColumnFilterMode == ColumnFilterMode.DisplayText) {
- TextEdit textEdit = new TextEdit() { VerticalContentAlignment = settings.VerticalContentAlignment };
- settings.AssignViewInfoProperties(textEdit, Column);
- return textEdit;
- }
- ComboBoxEditSettings comboBoxEditSettings = settings as ComboBoxEditSettings;
- if(comboBoxEditSettings != null) {
- ComboBoxEdit comboBoxEdit = (ComboBoxEdit)comboBoxEditSettings.CreateEditor(false, EmptyDefaultEditorViewInfo.Instance);
- comboBoxEdit.ItemsSource = GetFilterComboBoxItems(comboBoxEdit.ItemsSource != null ? comboBoxEdit.ItemsSource : comboBoxEdit.Items);
- return comboBoxEdit;
- }
- return settings.CreateEditor(false, Column);
- }
- List<object> GetFilterComboBoxItems(IEnumerable items) {
- List<object> list = new List<object>();
- list.Add(new CustomComboBoxItem() { DisplayValue = string.Empty, EditValue = string.Empty });
- foreach(object item in items)
- list.Add(item);
- return list;
- }
- protected override void UpdateEditValue(BaseEdit editor) {
- editor.EditValue = Column.AutoFilterValue;
- }
- protected internal override bool PostEditor() {
- if(Edit.IsValueChanged) {
- Edit.FlushPendingEditActions();
- Column.AutoFilterValue = Edit.EditValue;
- }
- return true;
- }
- protected override void OnEditValueChanged() {
- if(Column.ImmediateUpdateAutoFilter)
- Column.AutoFilterValue = Edit.EditValue;
- }
- protected override void OnHiddenEditor() {
- Edit.EditValue = Column.AutoFilterValue;
- base.OnHiddenEditor();
- }
- protected override void OnColumnContentChanged(object sender, ColumnContentChangedEventArgs e) {
- if(e.Property == GridColumn.AutoFilterValueProperty) {
- Edit.EditValue = Column.AutoFilterValue;
- return;
- }
- if (e.Property == GridColumn.ColumnFilterModeProperty) {
- UpdateContent();
- return;
- }
- base.OnColumnContentChanged(sender, e);
- }
- protected override void SetDisplayTextProvider(BaseEdit newEdit) {
- }
- }
- public class NewItemRowCellEditor : CellEditor {
- protected override void OnEditValueChanged() {
- base.OnEditValueChanged();
- if(View.IsNewItemRowFocused && !View.DataProvider.IsNewItemRowEditing)
- (View as TableView).BeginNewItemRow();
- }
- protected override void OnPreviewKeyDown(KeyEventArgs e) {
- base.OnPreviewKeyDown(e);
- if(e.Key == Key.Enter && !IsEditorVisible)
- (View as TableView).MoveNextNewItemRowCell();
- }
- }
- public class CustomComboBoxItem : ICustomComboBoxItem {
- object displayValue;
- object editValue;
- public object DisplayValue {
- get { return displayValue; }
- set { displayValue = value; }
- }
- public object EditValue {
- get { return editValue; }
- set { editValue = value; }
- }
- }
- public interface IBaseEdit {
- void LockEditorFocus();
- void UnlockEditorFocus();
- bool NeedsKey(KeyEventArgs e);
- bool IsActivatingKey(KeyEventArgs e);
- void ProcessActivatingKey(KeyEventArgs e);
- bool IsReadOnly { get; set; }
- bool IsEditButtonsVisible { get; set; }
- bool IsEditorActive { get; }
- bool IsValueChanged { get; set; }
- EditMode EditMode { get; set; }
- object EditValue { get; set; }
- void SetKeyboardFocus();
- void SetValidationError(BaseValidationError validationError);
- bool IsChildElement(IInputElement element);
- void SetDisplayTemplate(ControlTemplate template);
- void SetEditTemplate(ControlTemplate template);
- void SelectAll();
- event EditValueChangedEventHandler EditValueChanged;
- void FlushPendingEditActions();
- bool DoValidate();
- }
- public class BaseEditWrapper : IBaseEdit {
- BaseEdit edit;
- public BaseEditWrapper(BaseEdit edit) {
- this.edit = edit;
- }
- void IBaseEdit.LockEditorFocus() {
- BaseEditHelper.LockEditorFocus(edit);
- }
- void IBaseEdit.UnlockEditorFocus() {
- BaseEditHelper.UnlockEditorFocus(edit);
- }
- bool IBaseEdit.NeedsKey(KeyEventArgs e) {
- return BaseEditHelper.GetNeedsKey(edit, e);
- }
- bool IBaseEdit.IsActivatingKey(KeyEventArgs e) {
- return BaseEditHelper.GetIsActivatingKey(edit, e);
- }
- void IBaseEdit.ProcessActivatingKey(KeyEventArgs e) {
- BaseEditHelper.ProcessActivatingKey(edit, e);
- }
- bool IBaseEdit.IsReadOnly { get { return edit.IsReadOnly; } set { edit.IsReadOnly = value; } }
- bool IBaseEdit.IsEditButtonsVisible { get { return edit.IsEditButtonsVisible; } set { edit.IsEditButtonsVisible = value; } }
- bool IBaseEdit.IsEditorActive { get { return edit.IsEditorActive; } }
- bool IBaseEdit.IsValueChanged { get { return BaseEditHelper.GetIsValueChanged(edit); } set { BaseEditHelper.SetIsValueChanged(edit, value); } }
- EditMode IBaseEdit.EditMode { get { return edit.EditMode; } set { edit.EditMode = value; } }
- object IBaseEdit.EditValue { get { return edit.EditValue; } set { edit.EditValue = value; } }
- void IBaseEdit.SetKeyboardFocus() {
- Keyboard.Focus(edit);
- }
- void IBaseEdit.SetValidationError(BaseValidationError validationError) {
- BaseEditHelper.SetValidationError(edit, validationError);
- }
- bool IBaseEdit.IsChildElement(IInputElement element) {
- return BaseEditHelper.GetIsChildElement(edit, element);
- }
- void IBaseEdit.SetDisplayTemplate(ControlTemplate template) {
- if(template != null)
- edit.DisplayTemplate = template;
- else
- edit.ClearValue(BaseEdit.DisplayTemplateProperty);
- }
- void IBaseEdit.SetEditTemplate(ControlTemplate template) {
- if(template != null)
- edit.EditTemplate = template;
- else
- edit.ClearValue(BaseEdit.EditTemplateProperty);
- }
- void IBaseEdit.SelectAll() {
- edit.SelectAll();
- }
- event EditValueChangedEventHandler IBaseEdit.EditValueChanged {
- add { edit.EditValueChanged += value; }
- remove { edit.EditValueChanged -= value; }
- }
- void IBaseEdit.FlushPendingEditActions() {
- BaseEditHelper.FlushPendingEditActions(edit);
- }
- bool IBaseEdit.DoValidate() {
- return edit.DoValidate();
- }
- }
- public class FakeBaseEdit : IBaseEdit {
- public static readonly IBaseEdit Instance = new FakeBaseEdit();
- private FakeBaseEdit () {
- }
- void IBaseEdit.LockEditorFocus() { }
- void IBaseEdit.UnlockEditorFocus() { }
- bool IBaseEdit.NeedsKey(KeyEventArgs e) {
- return true;
- }
- bool IBaseEdit.IsActivatingKey(KeyEventArgs e) {
- return false;
- }
- void IBaseEdit.ProcessActivatingKey(KeyEventArgs e) { }
- bool IBaseEdit.IsReadOnly { get { return true; } set { } }
- bool IBaseEdit.IsEditButtonsVisible { get { return false; } set { } }
- bool IBaseEdit.IsEditorActive { get { return false; } }
- bool IBaseEdit.IsValueChanged { get { return false; } set { } }
- EditMode IBaseEdit.EditMode { get { return EditMode.InplaceInactive; } set { } }
- object IBaseEdit.EditValue { get { return null; } set { } }
- void IBaseEdit.SetKeyboardFocus() { }
- void IBaseEdit.SetValidationError(BaseValidationError validationError) { }
- bool IBaseEdit.IsChildElement(IInputElement element) { return false; }
- void IBaseEdit.SetDisplayTemplate(ControlTemplate template) { }
- void IBaseEdit.SetEditTemplate(ControlTemplate template) { }
- void IBaseEdit.SelectAll() { }
- event EditValueChangedEventHandler IBaseEdit.EditValueChanged { add { } remove { } }
- void IBaseEdit.FlushPendingEditActions() { }
- bool IBaseEdit.DoValidate() { return true; }
- }
- }