protected virtual bool EndEditCore(bool validate, bool cancel)
        {
            if (this.endEditCore || !this.IsInEditMode)
            {
                this.RestoreValidationFlag();
                return(false);
            }
            this.endEditCore = true;
            GridCellElement currentCell = this.gridViewElement.CurrentView.CurrentCell;

            if (currentCell == null)
            {
                this.RestoreValidationFlag();
                return(false);
            }
            GridViewDataColumn columnInfo      = currentCell.ColumnInfo as GridViewDataColumn;
            RadItem            activeEditor1   = this.activeEditor as RadItem;
            GridCellElement    gridCellElement = (GridCellElement)null;

            if (activeEditor1 != null)
            {
                gridCellElement = activeEditor1.FindAncestor <GridCellElement>();
            }
            else
            {
                BaseGridEditor activeEditor2 = this.activeEditor as BaseGridEditor;
                if (activeEditor2 != null)
                {
                    gridCellElement = activeEditor2.EditorElement.FindAncestor <GridCellElement>();
                }
            }
            if (gridCellElement != null && gridCellElement.ColumnInfo != null && gridCellElement.ColumnInfo != currentCell.ColumnInfo)
            {
                cancel   = true;
                validate = false;
            }
            object result = this.activeEditor.Value;

            if (columnInfo is GridViewDecimalColumn && !RadDataConverter.Instance.EqualsNullValue(result, (IDataConversionInfoProvider)columnInfo) && (result != null && (object)result.GetType() != (object)columnInfo.DataType))
            {
                RadDataConverter.Instance.TryFormat(result, columnInfo.DataType, (IDataConversionInfoProvider)columnInfo, out result);
            }
            if (object.Equals(result, (object)string.Empty))
            {
                result = (object)null;
            }
            bool   flag1      = this.activeEditor.IsModified && this.editModeInitialized;
            bool   flag2      = true;
            object dataSource = this.GridViewElement.Template.DataSource;

            if (validate)
            {
                GridTableElement tableElement = currentCell.TableElement;
                tableElement.BeginUpdate();
                flag2 = !this.RaiseCellValidatingEvent(currentCell.RowInfo, currentCell.ColumnInfo, result, currentCell.Value);
                tableElement.EndUpdate(false);
            }
            if (!flag2 && !this.CloseEditorWhenValidationFails)
            {
                this.endEditCore = false;
                this.RestoreValidationFlag();
                BaseGridEditor activeEditor2 = this.activeEditor as BaseGridEditor;
                (activeEditor2 != null ? activeEditor2.EditorElement : this.activeEditor as RadElement)?.FindDescendant <RadTextBoxItem>()?.HostedControl.Focus();
                return(flag2);
            }
            if (cancel || !flag2)
            {
                object         obj           = currentCell.Value;
                BaseGridEditor activeEditor2 = this.activeEditor as BaseGridEditor;
                if (activeEditor2 != null)
                {
                    obj = RadDataConverter.Instance.Format(obj, activeEditor2.DataType, (IDataConversionInfoProvider)columnInfo);
                }
                this.activeEditor.Value = obj;
            }
            else if (!flag1 && columnInfo.DataSourceNullValue != null && RadDataConverter.Instance.EqualsNullValue(result, (IDataConversionInfoProvider)columnInfo))
            {
                flag1 = true;
            }
            this.activeEditor.EndEdit();
            if (this.gridViewElement.AutoSizeRows)
            {
                GridViewRowInfo rowInfo = currentCell.RowElement.RowInfo;
                rowInfo.SuspendPropertyNotifications();
                rowInfo.Height = this.oldRowHeight;
                rowInfo.ResumePropertyNotifications();
                this.oldRowHeight = -1;
            }
            if (currentCell != null)
            {
                ((IEditableCell)currentCell).RemoveEditor(this.activeEditor);
                if (!this.isValidating && currentCell.ElementTree != null && currentCell.ElementTree.Control.ContainsFocus)
                {
                    currentCell.GridViewElement.Focus();
                }
            }
            if (currentCell.RowInfo is GridViewNewRowInfo && currentCell.Value == null && result == DBNull.Value)
            {
                flag1 = false;
            }
            int num1 = 0;

            if (currentCell.ViewTemplate != null && currentCell.ViewTemplate.DataSource != null)
            {
                num1 = currentCell.ViewTemplate.DataSource.GetHashCode();
            }
            if (flag1 && !cancel && flag2)
            {
                this.gridViewElement.SuspendLayout(true);
                currentCell.Value = result;
                validate          = currentCell.ViewTemplate != null && (currentCell.ViewTemplate.DataSource != null && num1 == currentCell.ViewTemplate.DataSource.GetHashCode() || currentCell.RowInfo is GridViewNewRowInfo || flag1);
                if (currentCell != null && currentCell.RowInfo != null)
                {
                    currentCell.RowInfo.IsModified = true;
                }
                else
                {
                    this.ActiveEditor = (IInputEditor)null;
                    this.endEditCore  = false;
                    this.RestoreValidationFlag();
                    this.gridViewElement.ResumeLayout(true, true);
                    return(true);
                }
            }
            int num2 = 0;

            if (currentCell.ViewTemplate != null && currentCell.ViewTemplate.DataSource != null)
            {
                num2 = currentCell.ViewTemplate.DataSource.GetHashCode();
            }
            if (validate && num1 == num2)
            {
                this.RaiseCellValidatedEvent(currentCell.RowInfo, currentCell.ColumnInfo, currentCell.MasterTemplate.VirtualMode ? result : currentCell.Value);
            }
            IInputEditor activeEditor3 = this.ActiveEditor;

            this.ActiveEditor = (IInputEditor)null;
            if (currentCell.RowElement != null)
            {
                currentCell.RowElement.UpdateInfo();
            }
            this.endEditCore = false;
            if (flag1 && !cancel && flag2)
            {
                this.gridViewElement.ResumeLayout(true, true);
            }
            if (this.GridViewElement.Template.DataSource != dataSource)
            {
                this.GridViewElement.TableElement.Update(GridUINotifyAction.Reset);
            }
            GridViewCellEventArgs args = new GridViewCellEventArgs(currentCell.RowInfo, currentCell.ColumnInfo, activeEditor3);

            this.gridViewElement.Template.EventDispatcher.RaiseEvent <GridViewCellEventArgs>(EventDispatcher.CellEndEdit, (object)this, args);
            this.RestoreValidationFlag();
            return(true);
        }
        public virtual bool BeginEdit()
        {
            GridCellElement currentCell  = this.gridViewElement.CurrentView.CurrentCell;
            IEditableCell   editableCell = currentCell as IEditableCell;

            if (this.IsInEditMode || editableCell == null || (!editableCell.IsEditable || currentCell == null) || (currentCell.RowInfo == null || currentCell.ViewInfo.ChildRows.Count == 0 && currentCell.RowInfo is GridViewDataRowInfo))
            {
                return(false);
            }
            bool flag = this.IsPermanentEditor(currentCell.ColumnInfo.GetDefaultEditorType());

            this.editModeInitialized = false;
            IInputEditor inputEditor1 = flag ? editableCell.Editor : this.GetDefaultEditor((IEditorProvider)currentCell.ColumnInfo);

            if (inputEditor1 == null)
            {
                return(false);
            }
            this.ActiveEditor = inputEditor1;
            GridViewCellCancelEventArgs args = new GridViewCellCancelEventArgs(currentCell, this.activeEditor);

            this.gridViewElement.Template.EventDispatcher.RaiseEvent <GridViewCellCancelEventArgs>(EventDispatcher.CellBeginEdit, (object)this, args);
            if (args.Cancel)
            {
                this.ActiveEditor = (IInputEditor)null;
                return(false);
            }
            this.gridViewElement.CurrentView.EnsureCellVisible(currentCell.RowInfo, currentCell.ColumnInfo);
            this.gridViewElement.UpdateLayout();
            if (this.gridViewElement.CurrentCell == null || this.gridViewElement.CurrentCell.RowInfo == null)
            {
                return(false);
            }
            if (currentCell != this.gridViewElement.CurrentCell || this.ActiveEditor == null)
            {
                currentCell  = (GridCellElement)this.gridViewElement.CurrentCell;
                editableCell = currentCell as IEditableCell;
                IInputEditor inputEditor2 = this.IsPermanentEditor(currentCell.ColumnInfo.GetDefaultEditorType()) ? editableCell.Editor : this.GetDefaultEditor((IEditorProvider)currentCell.ColumnInfo);
                if (inputEditor2 == null)
                {
                    return(false);
                }
                this.ActiveEditor = inputEditor2;
            }
            if (currentCell.RowInfo is GridViewNewRowInfo)
            {
                currentCell.RowInfo.CallOnBeginEdit();
            }
            editableCell.AddEditor(this.activeEditor);
            BaseGridEditor activeEditor = this.ActiveEditor as BaseGridEditor;

            activeEditor?.SetIsInBeginEditMode(true);
            currentCell.UpdateLayout();
            if (this.gridViewElement.AutoSizeRows)
            {
                GridViewRowInfo rowInfo = currentCell.RowInfo;
                this.oldRowHeight = currentCell.RowInfo.Height;
                rowInfo.SuspendPropertyNotifications();
                rowInfo.Height = (int)currentCell.RowElement.DesiredSize.Height;
                rowInfo.ResumePropertyNotifications();
                currentCell.TableElement.ViewElement.UpdateRows();
            }
            this.InitializeEditor(this.activeEditor);
            activeEditor?.SetIsInBeginEditMode(false);
            this.activeEditor.BeginEdit();
            currentCell.RowElement.UpdateInfo();
            this.editModeInitialized = true;
            return(true);
        }