|
1 | | -# wpf-gridcontrol-coveredcells |
2 | | -This repository contains the samples that demonstrates various options in covered cell feature of wpf gridcontrol. |
| 1 | +# WPF GridControl CoveredCells |
| 2 | + |
| 3 | +This repository contains the samples that demonstrates various options in covered cell feature of [WPF GridControl](https://www.syncfusion.com/wpf-controls/excel-like-grid). |
| 4 | + |
| 5 | +### Creating covered cells using QueryCoveredRange event |
| 6 | + |
| 7 | +You can also covered the range of cells by using [QueryCoveredRange](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridControlBase.html#Syncfusion_Windows_Controls_Grid_GridControlBase_QueryCoveredRange) event. This event will be raised for all the cells and you can set the range of cells by using [Range](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridQueryCoveredRangeEventArgs.html#Syncfusion_Windows_Controls_Grid_GridQueryCoveredRangeEventArgs_Range) property. |
| 8 | + |
| 9 | +``` csharp |
| 10 | +//Triggering the QueryCoveredRange event |
| 11 | +grid.QueryCoveredRange += Grid_QueryCoveredRange; |
| 12 | + |
| 13 | +private void Grid_QueryCoveredRange(object sender, Syncfusion.Windows.Controls.Grid.GridQueryCoveredRangeEventArgs e) |
| 14 | +{ |
| 15 | + //Checking the cell to start covered range. |
| 16 | + if(e.CellRowColumnIndex.RowIndex == 2 && e.CellRowColumnIndex.ColumnIndex == 2) |
| 17 | + { |
| 18 | + //Set the range to be covered. |
| 19 | + e.Range = new CoveredCellInfo(2, 2, 5, 5); |
| 20 | + |
| 21 | + //Handled property has to be enabled to perform this customization. |
| 22 | + e.Handled = true; |
| 23 | + } |
| 24 | +} |
| 25 | +``` |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +### Find whether a cell in covered range |
| 30 | + |
| 31 | +When you want to find a cell in covered ranges, you can use the [GetCoveredCell](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.Controls.Grid.GridCoveredCellInfoCollection.html#Syncfusion_Windows_Controls_Grid_GridCoveredCellInfoCollection_GetCoveredCell_System_Int32_System_Int32_) method. If the specified cell with row index and column index is inside in `GetCoveredCell`, a range will be returned. |
| 32 | + |
| 33 | +``` csharp |
| 34 | +// Adding covered ranges |
| 35 | +grid.Model.CoveredRanges.Add(new CoveredCellInfo(2, 2, 5, 5)); |
| 36 | + |
| 37 | +//Find the covered ranges |
| 38 | +CoveredCellInfo coverRanges = grid.Model.CoveredRanges.GetCoveredCell(2, 3); |
| 39 | +MessageBox.Show("Cover range for cell (2,3) is " + "R" + coverRanges.Left + "C" + coverRanges.Top + ":" + "R" + coverRanges.Bottom + "C" + coverRanges.Right); |
| 40 | +``` |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | +### Remove covered range at run time |
| 45 | + |
| 46 | +You can remove the covered range at run time by using [Clear](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.CellGrid.CellSpanInfoCollection-1.html#Syncfusion_UI_Xaml_CellGrid_CellSpanInfoCollection_1_Clear) method. |
| 47 | + |
| 48 | +``` csharp |
| 49 | +//Removing the covered range from GridControl. |
| 50 | +grid.Model.CoveredRanges.Clear(); |
| 51 | +``` |
| 52 | + |
| 53 | +For example, If you want to remove the covered range at run time, create one button and set the Clear method for covered range in click event of button. |
| 54 | + |
| 55 | +#### XAML |
| 56 | +``` xml |
| 57 | +<Grid> |
| 58 | + <syncfusion:GridControl Name="grid" Margin="10,20,0,0" /> |
| 59 | + <Button Height="50" Width="100" Margin="400,200,0,0" Click="Button_Click" /> |
| 60 | +</Grid> |
| 61 | +``` |
| 62 | + |
| 63 | +#### C# |
| 64 | +``` csharp |
| 65 | +grid.Model.CoveredRanges.Add(new CoveredCellInfo(2, 2, 5, 5)); |
| 66 | +private void Button_Click(object sender, RoutedEventArgs e) |
| 67 | +{ |
| 68 | + grid.Model.CoveredRanges.Clear(); |
| 69 | + grid.InvalidateCells(); |
| 70 | +} |
| 71 | +``` |
| 72 | +The below image provides covered range at run time before removing |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | +The below image provides covered range at run time after removing |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | +### Extend covered range at run time |
| 81 | + |
| 82 | +You can extend the covered range at run time by using [Add](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.CellGrid.CellSpanInfoCollection-1.html#Syncfusion_UI_Xaml_CellGrid_CellSpanInfoCollection_1_Add__0_) method. |
| 83 | + |
| 84 | +For example, Create one button. Next, clear the current covered cell collection using `Clear` method and create new covered cell ranges by using `Add` method in this click event. |
| 85 | + |
| 86 | +**Note:** Before extend the covered cell range, you need to clear the covered range. |
| 87 | + |
| 88 | +``` csharp |
| 89 | +//Remove the current covered cell range |
| 90 | +grid.Model.CoveredRanges.Clear(); |
| 91 | +grid.InvalidateCells(); |
| 92 | +//Add new covered cell range |
| 93 | +grid.Model.CoveredRanges.Add(new CoveredCellInfo(2, 2, 7, 7)); |
| 94 | +``` |
| 95 | + |
| 96 | +The below image provides covered range at run time before extending. |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +The below image provides covered range at run time after extending. |
| 101 | + |
| 102 | + |
0 commit comments