コード例 #1
0
        internal bool RaiseRowValidate(RowColumnIndex currentCellIndex)
        {
            if (IsCurrentRowValidated)
            {
                return(true);
            }

            var dataRow = treeGrid.RowGenerator.Items.FirstOrDefault(item => item.RowIndex == currentCellIndex.RowIndex);

            if (dataRow == null)
            {
                return(true);
            }
            errorMessages = new Dictionary <string, string>();
            rowIndex      = dataRow.RowIndex;
            var treeNode       = treeGrid.View.Nodes.GetNode(dataRow.RowElement.DataContext);
            var validatingArgs = new TreeGridRowValidatingEventArgs(dataRow.RowElement.DataContext, currentCellIndex.RowIndex, errorMessages, treeGrid, treeNode);

            if (!treeGrid.RaiseRowValidatingEvent(validatingArgs))
            {
                dataRow.VisibleColumns.ForEach
                    (dataColumnBase =>
                {
                    if (dataColumnBase.TreeGridColumn == null || dataColumnBase.ColumnElement == null)
                    {
                        return;
                    }

                    var currentCell = dataColumnBase.ColumnElement as TreeGridCell;
                    if (currentCell == null)
                    {
                        return;
                    }

                    if (validatingArgs.ErrorMessages.ContainsKey(dataColumnBase.TreeGridColumn.MappingName))
                    {
                        currentCell.SetError(validatingArgs.ErrorMessages[dataColumnBase.TreeGridColumn.MappingName], false);
                    }
                    else
                    {
                        if (currentCell.HasError)
                        {
                            currentCell.RemoveError(false);
                        }
                    }
                });

                (dataRow.RowElement as TreeGridRowControl).SetError();
                if (!dataRow.IsEditing)
                {
                    treeGrid.SelectionController.CurrentCellManager.BeginEdit();
                }
                SetCurrentCellValidated(false);
                return(false);
            }
            else
            {
                RemoveError(dataRow, false);
            }

            var args = new TreeGridRowValidatedEventArgs(validatingArgs.RowData, validatingArgs.RowIndex, validatingArgs.ErrorMessages, treeGrid, treeNode);

            treeGrid.RaiseRowValidatedEvent(args);
            SetCurrentRowValidated(true);

            errorMessages = null;
            rowIndex      = -1;
            return(true);
        }