# Working With Slicers

Explore the capabilities of Spread for WinForms in working with slicers, including adding multiple slicers, selecting slicer items, and customizing slicer styles.

## Content

Spread for WinForms provides support for using slicers (visual filters) in the worksheet. Slicers enable users to perform quick filtration of the data in tables without using drop-down lists.
Users can have multiple "copies" of a slicer operating together on different worksheets. You can select an item or drag across a number of items by using the keyboard shortcuts "Ctrl + Click" or "Shift + Click" to include the filter items and the data for that item will be displayed in the report as per the specific requirements.

## Add a Slicer

To add a slicer in the worksheet, users first need to set the value of the [EnhancedShapeEngine](/spreadnet/api/latest/online-win/FarPoint.Win.Spread/FarPoint.Win.Spread.IFeatures.EnhancedShapeEngine.html) property to "true" in order to enable the new shape engine. After enabling the **EnhancedShapeEngine**, users can either use the [Add()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCaches.Add.html) method of the [ISlicerCaches](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCaches.html) interface or simply click anywhere on the table and select the "Insert" button on the ribbon bar to add a slicer to the worksheet.
A slicer contains a header, a caption, slicer items and a clear button. The following image shows a slicer added to the worksheet.
![Slicers example](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/add-slicer.png)
The following example code shows how to add a slicer in the spreadsheet.

```csharp
// Enable Shape Engine using EnhancedShapeEngine property to use the slicer feature
fpSpread1.Features.EnhancedShapeEngine = true;
// Add the Slicer
  private static void AddSlicer(IWorkbook WorkBook, IWorksheet WorkSheet)
{ 
// Initialize Data in worksheet
WorkSheet.Cells[0, 0].Text = "Name";
WorkSheet.Cells[0, 1].Text = "City";
WorkSheet.Cells[0, 2].Text = "Weight";
WorkSheet.Cells[1, 0].Text = "Bob";
WorkSheet.Cells[1, 1].Text = "NewYork";
WorkSheet.Cells[1, 2].Value = 80;
WorkSheet.Cells[2, 0].Text = "Betty";
WorkSheet.Cells[2, 1].Text = "Chicago";
WorkSheet.Cells[2, 2].Value = 72;
WorkSheet.Cells[3, 0].Text = "Alice";
WorkSheet.Cells[3, 1].Text = "Washington";
WorkSheet.Cells[3, 2].Value = 71;
// Create Table
ITable table = WorkSheet.Tables.Add("A1:C4", YesNoGuess.Yes);

// Add SlicerCache using the Column index
ISlicerCache slicerCache = WorkBook.SlicerCaches.Add(table, 0, "slicerCache");

// Add Slicer to SlicerCache
ISlicer slicer = slicerCache.Slicers.Add(WorkSheet, "slicer", "Name", 200, 20, 200, 200);
}
```

## Add Multiple Slicers

Users can also add multiple slicers to the worksheet by using the [Add()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCaches.Add.html) method of the [ISlicerCaches](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCaches.html) interface. The following image shows a spreadsheet with multiple slicers.
![Multiple Slicers Example](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/multiple-slicer.png)
The following example code shows how to add multiple slicers in a spreadsheet.

```csharp
// Enable Shape Engine using EnhancedShapeEngine property to use the slicer feature
fpSpread1.Features.EnhancedShapeEngine = true;
private static void AddMultipleSlicer(IWorkbook WorkBook, IWorksheet WorkSheet)
{
// Initialize Data in worksheet
  WorkSheet.Cells[0, 0].Text = "Name";
  WorkSheet.Cells[0, 1].Text = "City";
  WorkSheet.Cells[0, 2].Text = "Weight";
  WorkSheet.Cells[1, 0].Text = "Bob";
  WorkSheet.Cells[1, 1].Text = "NewYork";
  WorkSheet.Cells[1, 2].Value = 80;
  WorkSheet.Cells[2, 0].Text = "Betty";
  WorkSheet.Cells[2, 1].Text = "Chicago";
  WorkSheet.Cells[2, 2].Value = 72;
  WorkSheet.Cells[3, 0].Text = "Alice";
  WorkSheet.Cells[3, 1].Text = "Washington";
  WorkSheet.Cells[3, 2].Value = 71;
// Create Table
  ITable table = WorkSheet.Tables.Add("A1:C4", YesNoGuess.Yes);
  
// Add SlicerCache using the Column index
  ISlicerCache slicerCache = WorkBook.SlicerCaches.Add(table, 0, "slicerCache");
  
// Add Slicer to SlicerCache
  ISlicer slicer = slicerCache.Slicers.Add(WorkSheet, "slicer", "Name", 200, 20, 200, 200);
  
// Add another SlicerCache using the Column Name 
 ISlicerCache slicerCache2 = WorkBook.SlicerCaches.Add(table, "City", "slicerCache2");

// Add another Slicer to another SlicerCache
 ISlicer slicer2 = slicerCache2.Slicers.Add(WorkSheet, "slicer2", "City", 410, 20, 200, 200);
}
```

## Select Slicer Items

Users can select and deselect slicer items by setting the [Selected](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerItem.Selected.html) property of the [ISlicerItem](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerItem.html) interface to "true" or "false" respectively.
The following example code shows how to select slicer items in the spreadsheet.

```csharp
private static void Filter(IWorkbook WorkBook)
{
  WorkBook.SlicerCaches[0].SlicerItems["Bob"].Selected = false;
  WorkBook.SlicerCaches[0].SlicerItems["Betty"].Selected = true;
  WorkBook.SlicerCaches[0].SlicerItems["Alice"].Selected = false;
}
```

Alternatively, you can use the keyboard shortcut "Ctrl + Click" or "Alt+S" to enable the multi selection mode. Then, you can click on the specific sites to filter out the data of selected items. To select multiple slicer items, you simply need to click the first item on the slicer, drag the mouse pointer towards the last item and then all the items between the first and last item will be selected.

## Clear Slicer Filters

Users can also remove the slicer filters when they want to show all the data by using the [ClearAllFilters()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.ClearAllFilters.html) method, the [ClearManualFilter()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.ClearManualFilter.html) method and the [ClearDateFilter()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.ClearDateFilter.html) method of the [ISlicerCache](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.html) interface. Alternatively, you can also click the "Clear Filter" button at the top right of the slicer or use the keyboard shortcut "Alt + C" to clear slicer filters from the spreadsheet.

The following example code shows how to clear slicer filters from the spreadsheet.

```csharp
private static void ClearFilter(IWorkbook WorkBook)
{
// Clear all filters from the Slicer
WorkBook.SlicerCaches[0].ClearAllFilters();
}
```

## Modify Slicer Settings

Users can also modify slicer settings as per their specific preferences by using the [Caption](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.Caption.html) property of the [ISlicer](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.html) interface and the [SortItems](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.SortItems.html) property of the [ISlicerCache](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.html) interface.
The following image shows the slicer with changed slicer caption and modified sorting order (names are showing up in the descending order).
![Slicer wtih modified slicer caption and sorting order](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/modify-slicer-settings.png)
The following example code shows how to modify slicer settings in the spreadsheet.

```csharp
private static void ModifySlicerSetting(IWorkbook WorkBook, IWorksheet WorkSheet)
 {
  // Change the Caption Name
  WorkSheet.Slicers["slicer"].Caption = "Name Changed";
  
  // Change the Sorting Order
  WorkBook.SlicerCaches["slicerCache"].SortItems = SlicerSort.Descending;
}
```

## Change Slicer Formatting

Users can also modify the formatting of the slicer by using the [NumberOfColumns](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.NumberOfColumns.html) property (to set the number of columns), the [Width](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.Width.html) property (to set the width of the slicer), the [Height](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.Height.html) property (to set the height of the slicer), the [ColumnWidth](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.ColumnWidth.html) property (to set the width of the columns), the [RowHeight](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.RowHeight.html) property (to set the height of the rows) and the [DisplayHeader](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.DisplayHeader.html) property (to configure the visibility of the header) of the [ISlicer](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.html) interface.
The following image shows a slicer with custom formatting.
![Slicer with custom formatting](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/change-slicer-formatting.png)
The following example code shows how to change slicer formatting in the spreadsheet.

```csharp
private static void ChangeSlicerFormatting(IWorksheet WorkSheet)
{
// Change Slicer Formatting
WorkSheet.Slicers["slicer"].NumberOfColumns = 2;
WorkSheet.Slicers["slicer"].Width = 250;
WorkSheet.Slicers["slicer"].Height = 150;
WorkSheet.Slicers["slicer"].ColumnWidth = 100;
WorkSheet.Slicers["slicer"].RowHeight = 70;
WorkSheet.Slicers["slicer"].DisplayHeader = false;
}
```

## Customize Slicer Style

Users can customize the slicer style as per their specific preferences by defining a custom style, setting the [ShowAsAvailableSlicerStyle](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.ITableStyle.ShowAsAvailableSlicerStyle.html) property of the [ITableStyle](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.ITableStyle.html) interface to true and applying the custom style to the slicer.
The following image shows a slicer with custom font style, font size and font color configured in the spreadsheet.
![Slicer with customized style](https://cdn.mescius.io/document-site-files/images/2238e618-a1fb-45a6-9ce5-9a4157bd2931/images/customize-slicer-style.png)
The following example code shows how to customize slicer styles in the spreadsheet.

```csharp
private static void CustomizeSlicerStyle(IWorkbook WorkBook, IWorksheet WorkSheet)
{ 
// Set Custom Style to Slicer
ITableStyle slicerStyle = WorkBook.TableStyles.Add("CustomStyle1");

// Enable ShowAsAvailableSlicerStyle to true to set custom style to Slicer
slicerStyle.ShowAsAvailableSlicerStyle = true;
slicerStyle.TableStyleElements[TableStyleElementType.SelectedItemWithData].Font.Name = "Arial";
slicerStyle.TableStyleElements[TableStyleElementType.SelectedItemWithData].Font.Bold = true;
slicerStyle.TableStyleElements[TableStyleElementType.SelectedItemWithData].Font.Italic = true;
slicerStyle.TableStyleElements[TableStyleElementType.SelectedItemWithData].Font.Size = 20;
slicerStyle.TableStyleElements[TableStyleElementType.SelectedItemWithData].Font.Color = GrapeCity.Spreadsheet.Color.FromThemeColor(GrapeCity.Core.ThemeColors.Accent3);
WorkSheet.Slicers["slicer"].Style = slicerStyle;
}
```

## Delete Slicer

Users can delete the slicer from the spreadsheet by using the [Delete()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.Delete.html) method of the [ISlicer](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicer.html) interface.
If you want to delete the slicer cache and all its slicers, you can use the [Delete()](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.Delete.html) method of the [ISlicerCache](/spreadnet/api/latest/online-win/GrapeCity.Spreadsheet/GrapeCity.Spreadsheet.Slicers.ISlicerCache.html) interface.
The following example code shows how to delete a slicer from the spreadsheet.

```csharp
private static void DeleteSlicer(IWorkbook WorkBook)
{
// Delete Slicer
WorkBook.SlicerCaches["slicerCache"].Slicers["slicer"].Delete();
}
```