Spread Windows Forms 7.0 Product Documentation
Working with Selections
Support Options
Spread Windows Forms 7.0 Product Documentation > Developer's Guide > Customizing Sheet Interaction > Customizing User Selection of Data > Working with Selections

Glossary Item Box

When a user selects a range of cells, that range of cells can have a separate background color and foreground color to distinguish it from the other cells in the spreadsheet. The range is called a selection. There are many aspects of selections that you can manage programmatically. In code you can add and remove selections and you can find out what is selected. This topic summarizes some of the tasks you can perform with selections in code.

To select all the cells in a sheet use the RowCount and ColumnCount properties for that sheet, as in this line of code: FpSpread1.ActiveSheet.Models.Selection.SetSelection(0, 0, FpSpread1.ActiveSheet.RowCount, FpSpread1.ActiveSheet.ColumnCount)

The DefaultSheetSelectionModel class (and IDisjointSelection interface) GetSelections method returns -1 for either the RowCount or the ColumnCount if all the cells in that row or column are selected, as when the end user clicks on a header to make a selection.

For information on the underlying model for selections, refer to Understanding the Selection Model.

Using a Shortcut

To add a selection, use the AddSelection method from the Sheets shortcut, specifying the necessary parameters.

Example

This example code selects two ranges of cells.

C# Copy Code
// Set the sheet to allow multiple range selections.
fpSpread1.Sheets[0].SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.MultiRange;
// Select cells C3 through D4.
fpSpread1.Sheets[0].AddSelection(2, 2, 2, 2);
// Select cells F6 through H8.
fpSpread1.Sheets[0].AddSelection(5, 5, 3, 3);
VB Copy Code
' Set the sheet to allow multiple range selections.
FpSpread1.Sheets(0).SelectionPolicy = FarPoint.Win.Spread.Model.SelectionPolicy.MultiRange
' Select cells C3 through D4.
FpSpread1.Sheets(0).AddSelection(2, 2, 2, 2)
' Select cells F6 through H8.
FpSpread1.Sheets(0).AddSelection(5, 5, 3, 3)

Using Code

To add a selection, use the AddSelection method from the Sheets shortcut, specifying the necessary parameters. Then assign the SheetView object to a sheet in the component.

Example

This example code selects two ranges of cells.

C# Copy Code
FarPoint.Win.Spread.SheetView newsheet=new FarPoint.Win.Spread.SheetView();
// Add two selections.newsheet.AddSelection(2, 2, 2, 2);
newsheet.AddSelection(5, 5, 3, 3);
// Assign the SheetView to a sheet in the component.
fpSpread1.Sheets[0] = newsheet;
VB Copy Code
Dim newsheet As New FarPoint.Win.Spread.SheetView()
' Add two selections.
newsheet.AddSelection(2, 2, 2, 2)
newsheet.AddSelection(5, 5, 3, 3)
' Assign the SheetView to a sheet in the component.
FpSpread1.Sheets(0) = newsheet

© 2002-2014 ComponentOne, a division of GrapeCity. All Rights Reserved.