/// <summary> /// Determines whether the specified row index is associated with any UnBoundRow's. /// </summary> /// <param name="dataGrid"> /// The SfDataGrid. /// </param> /// <param name="rowIndex"> /// The corresponding rowIndex to determine the UnBoundRow. /// </param> /// <returns> /// Returns <b>true</b> if the specified row index is UnBoundRow; otherwise, <b>false</b>. /// </returns> public static bool IsUnBoundRow(this SfDataGrid dataGrid, int rowIndex) { if (!dataGrid.UnBoundRows.Any()) { return(false); } var topUnBoundDataRowsCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top); var bottomUnBoundDataRowsCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom); var rowCount = dataGrid.VisualContainer.RowCount; var topTableSummaryRowsCount = dataGrid.GetTableSummaryCount(TableSummaryRowPosition.Top); var bottomTableSummaryRowsCount = dataGrid.View == null ? 0 : dataGrid.GetTableSummaryCount(TableSummaryRowPosition.Bottom); var frozenCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top, false); //, RowRegion.Header); var footerCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom, true); //,RowRegion.Footer); var topBodyCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top, true); //, RowRegion.Body); var bottomBodyCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom, false); //, RowRegion.Body); var bottomAddNewRow = !dataGrid.HasView ? 0 : dataGrid.AddNewRowPosition == AddNewRowPosition.Bottom ? 1 : 0; bottomAddNewRow += !dataGrid.HasView ? 0 : dataGrid.FilterRowPosition == FilterRowPosition.Bottom ? 1 : 0; var gridRows = !dataGrid.HasView ? 0 : (dataGrid.AddNewRowPosition == AddNewRowPosition.Top ? 1 : 0) + (dataGrid.FilterRowPosition == FilterRowPosition.Top ? 1 : 0); var headerLineCount = (!dataGrid.HasView ? dataGrid.VisualContainer.FrozenRows : dataGrid.HeaderLineCount) + gridRows; var headerIndex = !dataGrid.HasView ? dataGrid.StackedHeaderRows.Count : dataGrid.GetHeaderIndex(); if ((rowIndex >= headerLineCount && rowIndex < (headerLineCount + topBodyCount)) // TopBodyCount Condition Checking || (rowIndex > headerIndex && rowIndex <= (headerIndex + frozenCount)) // FrozenCount Condition Checking || ((rowIndex < (rowCount - (bottomTableSummaryRowsCount + footerCount + bottomAddNewRow))) && (rowIndex >= (rowCount - (bottomTableSummaryRowsCount + footerCount + bottomBodyCount + bottomAddNewRow)))) // Bootom body condition chceking || (rowIndex >= (rowCount - footerCount) && rowIndex < rowCount)) // Footer count condition checking. { return(true); } return(false); }
/// <summary> /// Resolves row index for the specified <see cref="Syncfusion.UI.Xaml.Grid.GridUnBoundRow"/>. /// </summary> /// <param name="DataGrid"> /// The SfDataGrid. /// </param> /// <param name="unBoundRow"> /// Specifies the UnBoundRow to get its corresponding row index. /// </param> /// <returns> /// Returns the row index of the specified UnBoundRow. /// </returns> public static int ResolveUnboundRowToRowIndex(this SfDataGrid DataGrid, GridUnBoundRow unBoundRow) { if (!DataGrid.UnBoundRows.Any()) { return(-1); } if (unBoundRow.Position == UnBoundRowsPosition.Top) { //var rows = DataGrid.UnBoundRows.Where(ubr => ubr.Position == unBoundRow.Position && ubr.ShowBelowSummary == unBoundRow.ShowBelowSummary); if (!unBoundRow.ShowBelowSummary) { return(DataGrid.GetHeaderIndex() + unBoundRow.UnBoundRowIndex + 1); } else { return(DataGrid.HeaderLineCount + (DataGrid.AddNewRowPosition == AddNewRowPosition.Top ? 1 : 0) + (DataGrid.FilterRowPosition == FilterRowPosition.Top ? 1 : 0) + unBoundRow.UnBoundRowIndex); } } else { if (!unBoundRow.ShowBelowSummary) { return(DataGrid.VisualContainer.RowCount - (DataGrid.GetTableSummaryCount(TableSummaryRowPosition.Bottom) + (DataGrid.AddNewRowPosition == AddNewRowPosition.Bottom ? 1 : 0) + (DataGrid.FilterRowPosition == FilterRowPosition.Bottom ? 1 : 0) + DataGrid.GetUnBoundRowsCount(unBoundRow.Position)) + unBoundRow.UnBoundRowIndex); } else { return(DataGrid.VisualContainer.RowCount - DataGrid.UnBoundRows.FooterUnboundRowCount + unBoundRow.UnBoundRowIndex); } } }
/// <summary> /// Gets the UnBoundRow for the specified row index. /// </summary> /// <param name="dataGrid"> /// The SfDataGrid. /// </param> /// <param name="rowIndex"> /// The row index to get the UnBoundRow. /// </param> /// <returns> /// Returns the corresponding <see cref="Syncfusion.UI.Xaml.Grid.GridUnBoundRow"/> for the specified row index. /// </returns> public static GridUnBoundRow GetUnBoundRow(this SfDataGrid dataGrid, int rowIndex) { if (!dataGrid.UnBoundRows.Any()) { return(null); } var row = dataGrid.UnBoundRows.FirstOrDefault(urow => urow.RowIndex == rowIndex); if (row != null) { return(row); } else { var frozenCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top, false); //, RowRegion.Header); var footerCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom, true); //, RowRegion.Footer); var topBodyCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Top, true); //, RowRegion.Body); var bottomBodyCount = dataGrid.GetUnBoundRowsCount(UnBoundRowsPosition.Bottom, false); //, RowRegion.Body); var topTableSummaryRowsCount = dataGrid.GetTableSummaryCount(TableSummaryRowPosition.Top); var bottomTableSummaryRowsCount = !dataGrid.HasView ? 0 : dataGrid.GetTableSummaryCount(TableSummaryRowPosition.Bottom); var gridRows = !dataGrid.HasView ? 0 : (dataGrid.AddNewRowPosition == AddNewRowPosition.Top ? 1 : 0) + (dataGrid.FilterRowPosition == FilterRowPosition.Top ? 1 : 0); var headerLineCount = (!dataGrid.HasView ? dataGrid.VisualContainer.FrozenRows : dataGrid.HeaderLineCount) + gridRows; var headerIndex = !dataGrid.HasView ? dataGrid.StackedHeaderRows.Count : dataGrid.GetHeaderIndex(); var rowCount = dataGrid.VisualContainer.RowCount; var bottomAddNewRow = !dataGrid.HasView ? 0 : dataGrid.AddNewRowPosition == AddNewRowPosition.Bottom ? 1 : 0; bottomAddNewRow += !dataGrid.HasView ? 0 : dataGrid.FilterRowPosition == FilterRowPosition.Bottom ? 1 : 0; if (rowIndex > headerIndex && rowIndex <= (headerIndex + frozenCount)) // FrozenCount Condition Checking { return(dataGrid.UnBoundRows.FirstOrDefault(item => !item.ShowBelowSummary && item.Position == UnBoundRowsPosition.Top && item.UnBoundRowIndex == (rowIndex - (headerIndex + 1)))); } else if (rowIndex >= headerLineCount && rowIndex < (headerLineCount + topBodyCount)) // TopBodyCount Condition Checking { return(dataGrid.UnBoundRows.FirstOrDefault(item => item.ShowBelowSummary && item.Position == UnBoundRowsPosition.Top && item.UnBoundRowIndex == (rowIndex - headerLineCount))); } else if (rowIndex >= (rowCount - footerCount) && rowIndex < rowCount) // Footer count condition checking. { return(dataGrid.UnBoundRows.FirstOrDefault(item => item.ShowBelowSummary && item.Position == UnBoundRowsPosition.Bottom && item.UnBoundRowIndex == ((rowIndex + footerCount) - rowCount))); } else if ((rowIndex < (rowCount - (bottomTableSummaryRowsCount + footerCount + bottomAddNewRow))) && (rowIndex >= (rowCount - (bottomTableSummaryRowsCount + footerCount + bottomBodyCount + bottomAddNewRow)))) // Bootom body condition chceking { return(dataGrid.UnBoundRows.FirstOrDefault(item => !item.ShowBelowSummary && item.Position == UnBoundRowsPosition.Bottom && item.UnBoundRowIndex == ((rowIndex + bottomBodyCount + bottomAddNewRow + bottomTableSummaryRowsCount + footerCount) - rowCount))); } } return(null); }
internal void DoActionOnMouseMove(Point pp, GridHeaderCellControl headerCell) #endif { bool isLastColumnHidden = false; #if !WPF double hScrollChange = 0; for (int i = 0; i < this.dataGrid.VisualContainer.FrozenColumns; i++) { hScrollChange += this.dataGrid.VisualContainer.ColumnWidths[i]; } // since panel x moves to negative the resizing not properly working, so Abs removed for x calculation WRT-1311, skipping for negative shrinking for first column. var pointerPoint = new Point((pp.Position.X - (dataGrid.VisualContainer.HScrollBar.Value - hScrollChange)), Math.Abs(pp.Position.Y - dataGrid.VisualContainer.VScrollBar.Value)); if (this.isHovering && pp.Properties.IsLeftButtonPressed && this.dragLine != null) { var delta = 0.0d; int repeatCount; bool isHidden; isHidden = isFirstColumnHidden ? dataGrid.VisualContainer.ColumnWidths.GetHidden(dragLine.LineIndex - 1, out repeatCount) : dataGrid.VisualContainer.ColumnWidths.GetHidden(dragLine.LineIndex + 1, out repeatCount); delta = isFirstColumnHidden ? pointerPoint.X : pointerPoint.X - dragLine.Corner; delta = Math.Floor(delta); #else if (this.isHovering && this.dragLine != null && (headerCell.isMouseLeftButtonPressed || headerCell.isTouchPressed)) { //After hiding the column by resizing the column in AddNewRow with edit mode, when pressing enter key rendering issue has been shown in //above AddNewRow because the CurrentRowIndex is not updated due the Current column is in Hidden state. Hence the current cell is //edited and New row value has been committed. CurrentCellEndEdit(); //Above code raises CurrentCellValidating if customer shows MessageBox then release capture lost and dragline will be null. if (dragLine == null) { return; } var delta = 0.0d; int repeatCount; bool isHidden; isHidden = isFirstColumnHidden ? dataGrid.VisualContainer.ColumnWidths.GetHidden(dragLine.LineIndex - 1, out repeatCount) : dataGrid.VisualContainer.ColumnWidths.GetHidden(dragLine.LineIndex + 1, out repeatCount); delta = isFirstColumnHidden ? pp.X : pp.X - dragLine.Corner; #endif double width = Math.Max(0, dragLine.Size + delta); var args = new ResizingColumnsEventArgs(this.dataGrid) { ColumnIndex = dragLine.LineIndex, Width = width }; if (isHidden && dataGrid.AllowResizingHiddenColumns && #if !WPF Window.Current.CoreWindow.PointerCursor.Type == UnhideCursor #else headerCell.Cursor == UnhideCursor #endif ) { if (delta <= 0) //WPF-16041 added this condition to sync cursor and action when unhidden last column { isLastColumnHidden = true; } if (delta <= 2 && !isLastColumnHidden) { return; } var hiddenLineIndex = dragLine.LineIndex + 1; if (isFirstColumnHidden) { hiddenLineIndex = 0; } var columnIndex = this.dataGrid.ResolveToGridVisibleColumnIndex(hiddenLineIndex); dataGrid.GridColumnSizer.Suspend(); dataGrid.Columns[columnIndex].Width = delta; dataGrid.GridColumnSizer.Resume(); if (dataGrid.Columns[columnIndex].IsHidden && delta <= 0) { dataGrid.GridColumnSizer.Suspend(); dataGrid.Columns[columnIndex].IsHidden = false; dataGrid.GridColumnSizer.Resume(); if (!dataGrid.Columns[columnIndex].IsHidden) { var index = this.dataGrid.ResolveToScrollColumnIndex(this.dataGrid.Columns.IndexOf(dataGrid.Columns[columnIndex])); this.dataGrid.VisualContainer.ColumnWidths.SetHidden(index, index, false); //Need to call ScrollInView to bring the hidden column into view while hiding/unhiding this.dataGrid.VisualContainer.ScrollColumns.ScrollInView(index, -delta); } if (dataGrid.AllowResizingColumns && dataGrid.AllowResizingHiddenColumns) { this.dataGrid.ColumnResizingController.ProcessResizeStateManager(dataGrid.Columns[columnIndex]); } this.dataGrid.VisualContainer.NeedToRefreshColumn = true; this.dataGrid.VisualContainer.InvalidateMeasureInfo(); if (this.dataGrid.GridColumnDragDropController != null) { this.dataGrid.GridColumnDragDropController.ColumnHiddenChanged(dataGrid.Columns[columnIndex]); } } else { dataGrid.Columns[columnIndex].IsHidden = false; } this.dataGrid.RowGenerator.UpdateCellStyle(columnIndex); #if !WPF var cursor = CoreCursorType.Arrow; if (delta >= 0) { dragLine = HitTest(new Point(pointerPoint.X, pointerPoint.Y), out cursor); } else // WPF-16041 Since delta value is negative,need to calculate the dragline through GetVisibleAtLineIndex() for the lastcolumn { dragLine = dataGrid.VisualContainer.ScrollColumns.GetVisibleLineAtLineIndex(hiddenLineIndex); cursor = ResizingCursor; } if (cursor != CoreCursorType.Arrow) { SetPointerCursor(cursor); } #else var cursor = headerCell.Cursor; if (dragLine != null && dragLine.LineIndex != hiddenLineIndex) { //dragline will be null when unhiding last column with ColumnSizer - AutoLastColumnFill as it is not inside ViewPort dragLine = dataGrid.VisualContainer.ScrollColumns.GetVisibleLineAtLineIndex(hiddenLineIndex); cursor = ResizingCursor; } SetPointerCursor(cursor, headerCell); #endif if (!double.IsNaN(headerCell.Column.MinimumWidth)) { delta = Math.Max(delta, headerCell.Column.MinimumWidth); } if (!double.IsNaN(headerCell.Column.MaximumWidth)) { delta = Math.Min(delta, headerCell.Column.MaximumWidth); } //WPF-16041 Since delta is negative for last column, change the delta sign and set to Width //delta value switched to positive only when last column is hidden. Other cases, it won't hit if ((dragLine != null) && delta <= 0) { args = new ResizingColumnsEventArgs(this.dataGrid) { ColumnIndex = dragLine.LineIndex, Width = -delta } } ; else if (dragLine != null) { args = new ResizingColumnsEventArgs(this.dataGrid) { ColumnIndex = dragLine.LineIndex, Width = delta } } ; } if (dragLine != null && !this.dataGrid.RaiseResizingColumnsEvent(args)) { var headerRow = dataGrid.RowGenerator.Items.FirstOrDefault(row => row.RowIndex == dataGrid.GetHeaderIndex()); var columnBase = headerRow.VisibleColumns.FirstOrDefault(col => col.ColumnIndex == (dragLine.LineIndex)); if (columnBase != null && columnBase.ColumnElement is GridHeaderCellControl) { var column = (columnBase.ColumnElement as GridHeaderCellControl).Column; if (dragLine.LineIndex > dataGrid.FrozenColumnCount) { dataGrid.VisualContainer.ScrollColumns.SetLineResize(dragLine.LineIndex, ComputeResizingWidth(column, args.Width != 0 ? args.Width : 1)); } else { column.Width = ComputeResizingWidth(column, args.Width != 0 ? args.Width : 1); } } isFirstColumnHidden = false; } } else { this.isHovering = false; #if !WPF Point point = pointerPoint; var cursor = ResizingCursor; #else Point point = pp; var cursor = headerCell.Cursor; #endif #if !WPF var hit = HitTest(pointerPoint, out cursor); if (hit != null && cursor != CoreCursorType.Arrow) #else var hit = HitTest(pp, out cursor); //When LineIndex returns the first column index, this condition fails hence the greater than or equal to condition is added. if (hit != null && (cursor == UnhideCursor || hit.LineIndex >= dataGrid.GetFirstColumnIndex())) #endif { var lineIndex = hit.LineIndex; if (cursor == UnhideCursor) { lineIndex++; int count; if (this.dataGrid.VisualContainer.ColumnWidths.GetHidden(lineIndex, out count)) { lineIndex += count - 1; } else { lineIndex--; } } var index = this.dataGrid.ResolveToGridVisibleColumnIndex(lineIndex); if (index >= 0 && index < this.dataGrid.Columns.Count) { GridColumn column = this.dataGrid.Columns[index]; var lineindex = this.dataGrid.ResolveToScrollColumnIndex(this.dataGrid.Columns.IndexOf(column)); if (!this.CanResizeColumn(column)) { return; } #if WPF this.SetPointerCursor(cursor, headerCell); #else this.SetPointerCursor(cursor); #endif } } bool edgeHit = point.X < 5.0 && point.X > 0; if (hit == null && edgeHit) { hit = new VisibleLineInfo(0, 0, 0, point.X, 0, true, false); } if (hit != null || edgeHit) { var row = this.dataGrid.VisualContainer.ScrollRows.GetVisibleLineAtPoint(point.Y); if (row != null && row.IsHeader) { this.isHovering = true; } } #if !WPF if (!isHovering && Window.Current.CoreWindow.PointerCursor.Type != CoreCursorType.Arrow) { SetPointerCursor(CoreCursorType.Arrow); } #else if (!isHovering && headerCell.Cursor != Cursors.Arrow && (!headerCell.isMouseLeftButtonPressed || !headerCell.isTouchPressed)) { SetPointerCursor(Cursors.Arrow, headerCell); } #endif } }