Beispiel #1
0
        internal bool RaiseRowValidate(RowColumnIndex currentCellIndex)
        {
            if (IsCurrentRowValidated)
            {
                return(true);
            }
#if WinRT || UNIVERSAL
            // In winrt and universal , the datagrid is from click notification. where we need to call parent validation to raise the cell validation for child grid.
            if (dataGrid is DetailsViewDataGrid)
            {
                var parentDataGrid = dataGrid.GetParentDataGrid();
                if (parentDataGrid.SelectedDetailsViewGrid == null || (parentDataGrid.SelectedDetailsViewGrid != null && dataGrid != parentDataGrid.SelectedDetailsViewGrid))
                {
                    return(parentDataGrid.ValidationHelper.RaiseRowValidate(parentDataGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex));
                }
            }
#endif
            if (dataGrid.IsInDetailsViewIndex(currentCellIndex.RowIndex))
            {
                if (dataGrid.SelectionController is GridBaseSelectionController)
                {
                    var currentDetailsViewGrid = (dataGrid.SelectionController as GridBaseSelectionController).GetCurrentDetailsViewGrid(dataGrid);
                    return(currentDetailsViewGrid.ValidationHelper.RaiseRowValidate(currentDetailsViewGrid.SelectionController.CurrentCellManager.CurrentRowColumnIndex));
                }
            }

            var dataRow = dataGrid.RowGenerator.Items.FirstOrDefault(item => item.RowIndex == currentCellIndex.RowIndex);
            if (dataRow == null)
            {
                return(true);
            }
            errorMessages = new Dictionary <string, string>();
            rowIndex      = dataRow.RowIndex;
            var validatingArgs = new RowValidatingEventArgs(dataRow.WholeRowElement.DataContext, currentCellIndex.RowIndex, errorMessages, dataGrid);

            if (!dataGrid.RaiseRowValidatingEvent(validatingArgs))
            {
                dataRow.VisibleColumns.ForEach
                    (datacolbase =>
                {
                    if (datacolbase.GridColumn == null)
                    {
                        return;
                    }
                    if (datacolbase.ColumnElement == null)
                    {
                        return;
                    }

                    var currentCell = datacolbase.ColumnElement as GridCell;
                    if (currentCell == null)
                    {
                        return;
                    }

                    if (validatingArgs.ErrorMessages.ContainsKey(datacolbase.GridColumn.MappingName))
                    {
                        currentCell.SetRowValidationError(validatingArgs.ErrorMessages[datacolbase.GridColumn.MappingName]);
                    }
                    else
                    {
                        if (currentCell.HasError)
                        {
                            currentCell.RemoveRowValidationError();
                        }
                    }
                });

                dataRow.WholeRowElement.SetError();
                if (!dataRow.IsEditing)
                {
                    dataGrid.SelectionController.CurrentCellManager.BeginEdit();
                }
                //WPF-31495 - Set CurrentCellVaildate only for isEditing datarow.
                if (dataRow.IsEditing)
                {
                    SetCurrentCellValidated(false);
                }
                return(false);
            }
            else
            {
                RemoveError(dataRow, false);
            }

            var args = new RowValidatedEventArgs(validatingArgs.RowData, validatingArgs.RowIndex, validatingArgs.ErrorMessages, dataGrid);
            dataGrid.RaiseRowValidatedEvent(args);
            SetCurrentRowValidated(true);
            //this.dataGrid.VisualContainer.SuspendManipulationScroll = false;
            errorMessages = null;
            rowIndex      = -1;
            return(true);
        }