Esempio n. 1
0
        /// <summary>
        /// Перемещает позицию в таблице на позицию необходимой строки и выделяет найденную строку
        /// </summary>
        /// <param name="grid">Таблица для обработки</param>
        /// <param name="filePredicate">Проверка на корректность файла</param>
        /// <param name="stringPredicate">Проверка на корректность строки</param>
        public static void ScrollToFileAndSelectString(this SfDataGrid grid, Predicate <IEditableFile> filePredicate,
                                                       Predicate <IOneString> stringPredicate)
        {
            int parentIndex = grid.View.Records.FindWithIndex(it => filePredicate(it.Data.As <IEditableFile>())).index;

            if (parentIndex == -1)
            {
                return;
            }

            SfDataGrid detailsGrid = grid.GetDetailsViewGridWUpd("Details", parentIndex);

            VisualContainer container = grid.GetVisualContainer();

            container.ScrollRows.ScrollInView(grid.ResolveToRowIndex(parentIndex));

            int childIndex = detailsGrid.View.Records.FindWithIndex(it => stringPredicate(it.Data as IOneString)).index;

            if (childIndex == -1)
            {
                return;
            }

            detailsGrid.SelectedIndex = childIndex;

            for (int i = 0; i < childIndex; i++)
            {
                container.ScrollRows.ScrollToNextLine();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Перемещает позицию в таблице на позицию необходимого файла и выделяет найденный файл
        /// </summary>
        /// <param name="grid">Таблица для обработки</param>
        /// <param name="filePredicate">Проверка на корректность файла</param>
        /// <param name="expandRecord">Нужно ли разворачивать таблицу вложенных элементов у файла</param>
        public static void ScrollToFileAndSelect(this SfDataGrid grid, Predicate <IEditableFile> filePredicate, bool expandRecord = true)
        {
            int parentIndex = grid.View.Records.FindWithIndex(it => filePredicate(it.Data.As <IEditableFile>())).index;

            if (parentIndex == -1)
            {
                return;
            }

            if (expandRecord)
            {
                grid.ExpandDetailsViewAt(parentIndex);
            }

            grid.SelectedIndex = parentIndex;

            VisualContainer container = grid.GetVisualContainer();

            container.ScrollRows.ScrollInView(grid.ResolveToRowIndex(parentIndex));
        }
        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;
            }
        }
Esempio n. 4
0
        public Task ScrollTo(PublishedAction publishedAction)
        {
            if (publishedAction == null)
            {
                publishedAction = PublishedAction;
            }
            if (DataGrid == null || publishedAction == null)
            {
                return(Task.CompletedTask);
            }
            // On récupère la liste des PublishedActions
            List <PublishedAction> publishedActions = new List <PublishedAction>();

            foreach (PublishedAction pAction in Publication.PublishedActions)
            {
                publishedActions.Add(pAction);
                if (pAction.LinkedPublication != null)
                {
                    foreach (PublishedAction pInnerAction in pAction.LinkedPublication.PublishedActions)
                    {
                        publishedActions.Add(pInnerAction);
                    }
                }
            }
            // On récupère l'index de l'élément
            publishedAction = publishedActions.FirstOrDefault(_ => _.PublishedActionId == publishedAction.PublishedActionId);
            if (publishedAction == null)
            {
                return(Task.CompletedTask);
            }
            int index = publishedActions.IndexOf(publishedAction) + 1;

            if (index == 0)
            {
                return(Task.CompletedTask);
            }

            var visualContainer          = DataGrid.GetVisualContainer();
            var scrollRows               = visualContainer.ScrollRows;
            var scrollOwner              = visualContainer.ScrollOwner;
            LineSizeCollection lineCount = visualContainer.RowHeights as LineSizeCollection;
            List <double>      heights   = new List <double>();

            for (int count = 0; count < lineCount.LineCount; count++)
            {
                var nestedDistances = lineCount.GetDistances(count);
                if (nestedDistances == null)
                {
                    if (lineCount[count] != 0)
                    {
                        heights.Add(lineCount[count]);
                    }
                }
                else
                {
                    for (int innerCount = 0; innerCount < nestedDistances.Count; innerCount++)
                    {
                        if (nestedDistances[innerCount] != 0)
                        {
                            heights.Add(nestedDistances[innerCount]);
                        }
                    }
                }
            }
            double vOffset = 0;

            for (int count = scrollRows.HeaderLineCount; count < index && count < heights.Count; count++)
            {
                vOffset += heights[count];
            }
            scrollOwner.ScrollToVerticalOffset(vOffset);
            return(Task.CompletedTask);
        }