/// <summary>
        /// Gets the record associated with the specified DetailsViewDataGrid.
        /// </summary>
        /// <param name="dataGrid">
        /// The SfDataGrid.
        /// </param>
        /// <param name="detailsViewDataGrid">
        /// Specifies the DetailsViewDataGrid to get its corresponding record entry.
        /// </param>
        /// <returns>
        /// The record associated with the specified DetailsViewDataGrid; returns null, if the DetailsViewDataGrid is null.
        /// </returns>
        public static object GetGridDetailsViewRecord(this SfDataGrid dataGrid, DetailsViewDataGrid detailsViewDataGrid)
        {
            if (detailsViewDataGrid == null || dataGrid.View == null)
            {
                return(null);
            }

            var index = dataGrid.GetGridDetailsViewRowIndex(detailsViewDataGrid);

            if (index == -1)
            {
                return(null);
            }

            RecordEntry record = null;

            if (dataGrid.GridModel.HasGroup)
            {
                var recordIndex = dataGrid.ResolveToGroupRecordIndexForDetailsView(index);
                record = dataGrid.View.TopLevelGroup.DisplayElements[recordIndex] as RecordEntry;
            }
            else
            {
                var recordIndex = dataGrid.ResolveToRecordIndex(index);
                record = dataGrid.View.Records[recordIndex];
            }
            return(record);
        }
        /// <summary>
        /// Method which creates DetailsViewDataGrid and Copy Properties from SourceDataGrid to DetailsViewDataGrid
        /// </summary>
        /// <param name="sourceDataGrid">Source DataGrid</param>
        /// <returns>DetailsViewDataGrid</returns>
        public DetailsViewDataGrid CopyPropertiesFromSourceDataGrid(SfDataGrid sourceDataGrid)
        {
            var destinationDataGrid = new DetailsViewDataGrid();

            CopyPropertiesFromSourceDataGrid(sourceDataGrid, destinationDataGrid);
            destinationDataGrid.InitializeDetailsViewDataGrid();
            ClonedDataGrid.Add(destinationDataGrid);
            // Set NotifyListener for DetailsViewDataGrid
            (destinationDataGrid as IDetailsViewNotifier).SetNotifierListener(new DetailsViewNotifyListener(sourceDataGrid));
            return(destinationDataGrid);
        }
        /// <summary>
        /// Gets the row index of the specified DetailsViewDataGrid.
        /// </summary>
        /// <param name="dataGrid">
        /// The SfDataGrid.
        /// </param>
        /// <param name="detailsViewDataGrid">
        /// The DetailsViewDataGrid to get its corresponding row index.
        /// </param>
        /// <returns>
        /// Returns the row index of the corresponding DetailsViewDataGrid.
        /// </returns>
        public static int GetGridDetailsViewRowIndex(this SfDataGrid dataGrid, DetailsViewDataGrid detailsViewDataGrid)
        {
            if (detailsViewDataGrid == null)
            {
                return(-1);
            }

            var dataRow = dataGrid.RowGenerator.Items.OfType <DetailsViewDataRow>().FirstOrDefault(
                row => row.DetailsViewDataGrid.Equals(detailsViewDataGrid));

            if (dataRow != null)
            {
                return(dataRow.RowIndex);
            }
            return(-1);
        }
        /// <summary>
        /// Copy Properties from SourceDataGrid to DetailsViewDataGrid
        /// </summary>
        /// <param name="sourceDataGrid">Source DataGrid</param>
        /// <param name="destinationDataGrid">DetailsViewDataGrid</param>
        /// <param name="needToClearProperties">whether need to clear DetailsViewDataGrid properties before assigning new properties from Source DataGrid</param>
        internal void CopyPropertiesFromSourceDataGrid(SfDataGrid sourceDataGrid, DetailsViewDataGrid destinationDataGrid, bool needToClearProperties = false)
        {
            if (needToClearProperties)
            {
                ClearDetailsViewDataGridProperties(destinationDataGrid);
            }
            // Copying the properties from sourceDataGrid to DetailsViewDataGrid
            CloneHelper.CloneProperties(sourceDataGrid, destinationDataGrid, typeof(SfGridBase));
            CloneHelper.CloneCollection(sourceDataGrid.Columns, destinationDataGrid.Columns, typeof(GridColumnBase));

            // Need to clone GroupColumnDescriptions first. Else, SortColumnDescriptions will be changed when GroupColumnDescriptions is changed
            CloneHelper.CloneCollection(sourceDataGrid.GroupColumnDescriptions, destinationDataGrid.GroupColumnDescriptions, typeof(GroupColumnDescription));
            CloneHelper.CloneCollection(sourceDataGrid.SortColumnDescriptions, destinationDataGrid.SortColumnDescriptions, typeof(SortColumnDescription));
            CloneHelper.CloneCollection(sourceDataGrid.GroupSummaryRows, destinationDataGrid.GroupSummaryRows, typeof(GridSummaryRow));
            CloneHelper.CloneCollection(sourceDataGrid.TableSummaryRows, destinationDataGrid.TableSummaryRows, typeof(GridSummaryRow));
            CloneHelper.CloneCollection(sourceDataGrid.UnBoundRows, destinationDataGrid.UnBoundRows, typeof(GridUnBoundRow));
            CloneHelper.CloneCollection(sourceDataGrid.CoveredCells, destinationDataGrid.CoveredCells, typeof(CoveredCellInfoCollection));
            // UWP-4752 Need to clone SortComparer from sourceDataGrid to DetailsViewDataGrid
            CloneHelper.CloneCollection(sourceDataGrid.SortComparers, destinationDataGrid.SortComparers, typeof(SortComparer));
            CloneHelper.CloneCollection(sourceDataGrid.StackedHeaderRows, destinationDataGrid.StackedHeaderRows, typeof(StackedHeaderRow));
            CloneHelper.CloneCollection(sourceDataGrid.DetailsViewDefinition, destinationDataGrid.DetailsViewDefinition, typeof(ViewDefinition));

#if WPF
            destinationDataGrid.SearchHelper.SearchText             = sourceDataGrid.SearchHelper.SearchText;
            destinationDataGrid.SearchHelper.AllowFiltering         = sourceDataGrid.SearchHelper.AllowFiltering;
            destinationDataGrid.SearchHelper.SearchType             = sourceDataGrid.SearchHelper.SearchType;
            destinationDataGrid.SearchHelper.CanHighlightSearchText = sourceDataGrid.SearchHelper.CanHighlightSearchText;
#endif

            // Copying the columns from sourceDataGrid to DetailsViewDataGrid
            foreach (var targetColumn in destinationDataGrid.Columns)
            {
                var sourceColumn = sourceDataGrid.Columns.FirstOrDefault(x => x.MappingName == targetColumn.MappingName);
                if (sourceColumn != null)
                {
                    CloneHelper.CloneCollection(sourceColumn.FilterPredicates, targetColumn.FilterPredicates, typeof(FilterPredicate));
                }
            }
            // Copying the StackedHeaderRows from sourceDataGrid to DetailsViewDataGrid
            foreach (var targetColumn in destinationDataGrid.StackedHeaderRows)
            {
                var sourceColumn = sourceDataGrid.StackedHeaderRows.ElementAt(destinationDataGrid.StackedHeaderRows.IndexOf(targetColumn));
                if (sourceColumn != null)
                {
                    CloneHelper.CloneCollection(sourceColumn.StackedColumns, targetColumn.StackedColumns, typeof(StackedColumn));
                }
            }

            //The following properties should be same for Parent grid and DetailsViewDataGrid.
            // Suspend sourceDataGrid notification since it will set properties for all DetailsViewDataGrids
            (sourceDataGrid as IDetailsViewNotifier).SuspendNotifyListener();
            sourceDataGrid.AllowSelectionOnPointerPressed = destinationDataGrid.AllowSelectionOnPointerPressed = _parentDataGrid.AllowSelectionOnPointerPressed;
            sourceDataGrid.SelectionMode                = destinationDataGrid.SelectionMode = _parentDataGrid.SelectionMode;
            sourceDataGrid.SelectionUnit                = destinationDataGrid.SelectionUnit = _parentDataGrid.SelectionUnit;
            sourceDataGrid.NavigationMode               = destinationDataGrid.NavigationMode = _parentDataGrid.NavigationMode;
            sourceDataGrid.DetailsViewPadding           = destinationDataGrid.DetailsViewPadding = _parentDataGrid.DetailsViewPadding;
            sourceDataGrid.ReuseRowsOnItemssourceChange = destinationDataGrid.ReuseRowsOnItemssourceChange = _parentDataGrid.ReuseRowsOnItemssourceChange;
#if WPF
            sourceDataGrid.UseDrawing = destinationDataGrid.UseDrawing = _parentDataGrid.UseDrawing;
#endif
            // Resume sourceDataGrid notification
            (sourceDataGrid as IDetailsViewNotifier).ResumeNotifyListener();
        }
 public DetailsViewLoadingAndUnloadingEventArgs(object dataGrid, DetailsViewDataGrid grid)
     : base(dataGrid)
 {
     DetailsViewDataGrid = grid;
 }