/// <summary> /// Возвращает таблицу вложенных элементов для таблицы, при этом раскрывая её и проматывая до её начала /// </summary> /// <param name="grid">Таблица, таблицу вложенных элементов которой нужно получить</param> /// <param name="relationalColumn">Название столбца с подробностями</param> /// <param name="recordIndex">Позиция записи в таблице</param> /// <param name="detailsColumn">Номер столбца в таблице вложенных элементов</param> public static SfDataGrid GetDetailsViewGridWUpd(this SfDataGrid grid, string relationalColumn, int recordIndex, int detailsColumn = 1) { int rowIndex = grid.ResolveToRowIndex(recordIndex); RecordEntry record = grid.View.Records[recordIndex]; if (!record.IsExpanded) { grid.ExpandDetailsViewAt(recordIndex); } int vIndex = grid.DetailsViewDefinition.FindWithIndex(it => it.RelationalColumn == relationalColumn).index + rowIndex + 1; grid.ScrollInView(new RowColumnIndex(vIndex, detailsColumn)); SfDataGrid view = grid.GetDetailsViewGrid(recordIndex, relationalColumn); if (view != null) { return(view); } grid.GetViewManager().BringIntoView(vIndex); grid.ScrollInView(new RowColumnIndex(rowIndex, detailsColumn)); return(grid.GetDetailsViewGrid(recordIndex, relationalColumn)); }
/// <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; } }