Spread Windows Forms 12.0 Product Documentation
Working with Deselections
Spread Windows Forms 12.0 Product Documentation > Developer's Guide > Customizing Sheet Interaction > Customizing User Selection and Deselection of Data > Working with Deselections

Spread for WinForms allows users to deselect the selected cells just like in Excel. In order to deselect a selection, users simply need to press and hold the ctrl key or cmd key on the keyboard and use the left, top, right or down arrow keys to deselect the cells that they want.

The deselection feature is useful especially when users mistakenly select extra cells within a spreadsheet. With large worksheets carrying huge amounts of data, it becomes cumbersome to deselect the unnecessary cells. Using the ctrl or cmd key, users can efficiently manage the entire process of deselection without having to start over; thus saving both time and efforts.

In order to demonstrate the working of deselection behavior, some example images are shared below:

  1. The following image depicts how a user can work with four selection areas when the deselection operation is executed inside the original selection.

  2. The following image depicts how a user can work with less than four selection areas when the deselection operation crosses the original selection.

  3. The following image depicts how a user can work with "No selections" when the deselection operation is executed within the original selection. In this scenario, after the deselection is performed, an active cell will be added at the beginning of the deselected selection.

After deselection, the new selection will be created as per the following rules:

Note: The deselect feature will be enabled only when the Default Sheet Selection Model is used, the SelectionUnit enumeration is set to "Cell" and the SelectionPolicy enumeration is set to "MultiRange".

Example

This example code shows how to work with deselections in a spreadsheet.

C#
Copy Code
fpSpread1_Sheet1.SelectionUnit = FarPoint.Win.Spread.Model.SelectionUnit.Cell;
fpSpread1_Sheet1.SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.MultiRange;
// Adding Selection
fpSpread1.Sheets[0].AddSelection(0, 0, 10, 5);
var sels = fpSpread1.ActiveSheet.GetSelections();
Console.WriteLine(sels.Length);
// Removing selection from selected range of cells
fpSpread1.Sheets[0].RemoveSelection(2, 2, 2, 1);
fpSpread1.Sheets[0].RemoveSelection(5, 1, 2, 3);
fpSpread1.Sheets[0].RemoveSelection(8, 3, 1, 1);

VB
Copy Code
fpSpread1_Sheet1.SelectionUnit = FarPoint.Win.Spread.Model.SelectionUnit.Cell
fpSpread1_Sheet1.SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.MultiRange
'Adding Selection
fpSpread1.Sheets(0).AddSelection(0, 0, 10, 5)
Dim sels = fpSpread1.ActiveSheet.GetSelections()
Console.WriteLine(sels.Length)
'Removing selection from selected range of cells
fpSpread1.Sheets(0).RemoveSelection(2, 2, 2, 1)
fpSpread1.Sheets(0).RemoveSelection(5, 1, 2, 3)
fpSpread1.Sheets(0).RemoveSelection(8, 3, 1, 1)