Exemplo n.º 1
0
 //UWP-711 When the previous row index is DetailsViewIndex, the autoscroller will fails. Hence the below method is used to get previous row index.
 private int GetPreviousRow(int previousIndex, SfDataGrid dataGrid)
 {
     previousIndex = VisualContainer.ScrollRows.GetPreviousScrollLineIndex(previousIndex);
     while (dataGrid.IsInDetailsViewIndex(previousIndex))
     {
         previousIndex = VisualContainer.ScrollRows.GetPreviousScrollLineIndex(previousIndex);
     }
     return(previousIndex);
 }
Exemplo n.º 2
0
 //UWP-711 When the next row index is DetailsViewIndex, the autoscroller will fails. Hence the below method is used to get next row index.
 private int GetNextRow(int currentIndex, SfDataGrid dataGrid)
 {
     currentIndex = VisualContainer.ScrollRows.GetNextScrollLineIndex(currentIndex);
     while (dataGrid.IsInDetailsViewIndex(currentIndex))
     {
         currentIndex = VisualContainer.ScrollRows.GetNextScrollLineIndex(currentIndex);
     }
     return(currentIndex);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Method used to get details viewdefinition index of the given DataGrid.
        /// </summary>
        /// <param name="dataGrid"> Specifies the data grid.</param>
        /// <param name="actualRowIdx">Specifies the integer type parameter.</param>
        /// <returns></returns>
        private int GetDetailsViewDefinitionIndex(SfDataGrid dataGrid, int actualRowIdx)
        {
            var counter0 = 0;

            for (int i = actualRowIdx; i > 0; i--)
            {
                if (!dataGrid.IsInDetailsViewIndex(i))
                {
                    break;
                }
                counter0++;
            }
            return(counter0);
        }
Exemplo n.º 4
0
        internal static int GetOrderForDetailsViewBasedOnIndex(this SfDataGrid dataGrid, int actualRowIdx)
        {
            // simply find the index which is not in DetailsView Index
            var counter0 = 0;

            for (int i = actualRowIdx; i > 0; i--)
            {
                if (!dataGrid.IsInDetailsViewIndex(i))
                {
                    break;
                }
                counter0++;
            }
            return(counter0);
        }
        private void ExpandAndSelectDetailsView(SfDataGrid dataGrid, int parentRowIndex, int childRowIndex, string relationalColumn)
        {
            //Checks whether the given index is parent row index or not.
            bool IsDetailsViewIndex = dataGrid.IsInDetailsViewIndex(parentRowIndex);

            if (IsDetailsViewIndex == true)
            {
                return;
            }
            //Gets the record of the parent row index.
            var record = dataGrid.View.Records[dataGrid.ResolveToRecordIndex(parentRowIndex)];
            //Gets the DetailsViewManager by using Reflection.
            var propertyInfo = dataGrid.GetType().GetField("DetailsViewManager", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            DetailsViewManager detailsViewManager = propertyInfo.GetValue(dataGrid) as DetailsViewManager;
            // Checks whether the parent record has the child grid or not by getting the child source and its count.
            var childSource         = detailsViewManager.GetChildSource(record.Data, relationalColumn);
            var GetChildSourceCount = detailsViewManager.GetType().GetMethod("GetChildSourceCount", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static);
            var ChildSourceCount    = GetChildSourceCount.Invoke(detailsViewManager, new object[] { childSource });

            if ((int)ChildSourceCount == 0)
            {
                return;
            }

            //Checks whether the record is Expanded or Collapsed.
            //When it is in the collapsed state, you need to expand the particular DetailsView based on the index.
            if (!record.IsExpanded)
            {
                dataGrid.ExpandDetailsViewAt(dataGrid.ResolveToRecordIndex(parentRowIndex));
            }
            //Gets the index of the DetailsView.
            int index = 0;

            foreach (var def in dataGrid.DetailsViewDefinition)
            {
                if (def.RelationalColumn == relationalColumn)
                {
                    index = dataGrid.DetailsViewDefinition.IndexOf(def);
                    index = parentRowIndex + index + 1;
                }
            }
            //Brings the parent row in the view.
            var rowcolumnIndex = new RowColumnIndex(index, 1);

            dataGrid.ScrollInView(rowcolumnIndex);
            //Gets the DetailsViewDataGrid by passing the corresponding rowindex and relation name.
            var detailsViewDataGrid = dataGrid.GetDetailsViewGrid(dataGrid.ResolveToRecordIndex(parentRowIndex), relationalColumn);
            //Checks whether the given index is currently in view or not.
            //When the specified index is not currently in view, you can bring that row in to the view by using the SfDataGrid.ScrollInView method.
            var firstline = dataGrid.GetVisualContainer().ScrollRows.GetVisibleLines().FirstOrDefault(line => line.Region == ScrollAxisRegion.Body);
            var lastline  = dataGrid.GetVisualContainer().ScrollRows.GetVisibleLines().LastOrDefault(line => line.Region == ScrollAxisRegion.Body);

            if (firstline.LineIndex >= index || lastline.LineIndex <= index)
            {
                //Brings the details view grid in to the view and sets the child grid's SelectedIndex as the ChildRowIndex.
                if (record != null && record.IsExpanded)
                {
                    if (detailsViewDataGrid == null)
                    {
                        detailsViewManager.BringIntoView(index);
                        detailsViewDataGrid = dataGrid.GetDetailsViewGrid(dataGrid.ResolveToRecordIndex(parentRowIndex), relationalColumn);
                    }
                }
            }

            if (detailsViewDataGrid != null)
            {
                detailsViewDataGrid.SelectedIndex = childRowIndex;
            }
        }
Exemplo n.º 6
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);
        }