Exemplo n.º 1
0
        private void CustomStackLayoutRenderer_PointerReleased(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)
        {
            var pointerPoint = e.GetCurrentPoint(this);

            point.Y = pointerPoint.Position.Y;
            point.X = pointerPoint.Position.X;
            var rowColumnIndex = SfDataGridHelpers.PointToCellRowColumnIndex(grid, point);
            var model          = (GridModel)grid.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("GridModel")).GetValue(grid);

            rowdata = SfDataGridHelpers.GetRowGenerator(grid).Items.FirstOrDefault(x => x.RowIndex == rowColumnIndex.RowIndex);
            if (rowdata != null)
            {
                wholeRowElement = (VirtualizingCellsControl)rowdata.GetType().GetRuntimeFields().FirstOrDefault(x => x.Name.Equals("WholeRowElement")).GetValue(rowdata);
                wholeRowElement.BackgroundColor = Xamarin.Forms.Color.White;
            }
        }
        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.º 3
0
        /// <summary>
        /// Возвращает <see cref="DetailsViewManager"/> таблицы
        /// </summary>
        /// <param name="grid">Таблица, объект которой нужно получить</param>
        public static DetailsViewManager GetViewManager(this SfDataGrid grid)
        {
            FieldInfo propertyInfo = grid.GetType().GetField("DetailsViewManager", BindingFlags.Instance | BindingFlags.NonPublic);

            return(propertyInfo?.GetValue(grid) as DetailsViewManager);
        }