Working with Selections
Spread WinRT Documentation > Developer's Guide > Managing the User Interface > Working with Selections

You can select cells, rows, columns, or multiple ranges in the control. You can specify what the user is allowed to select with the SelectionPolicy property. You can further restrict the selection with the SelectionUnit property to a single row, column, or cell.

You can specify selection colors with the SelectionBorderColorSelectionBackground, or SelectionBorderThemeColor property.

Click and drag with the left mouse button to select a block of cells, columns, or rows. You can use the mouse click and Ctrl key to select multiple ranges of cells. Navigation keys are listed in the Using Keyboard Navigation.

The following image displays multiple selected blocks of cells:

You can use the SetSelection or AddSelection method to create a selection in code.

Using Code

This example creates multiple selections.

CS
Copy Code

private void Grid_Loaded_1(object sender, RoutedEventArgs e)
        {
            GrapeCity.Xaml.SpreadSheet.Data.CellRange cellr = new GrapeCity.Xaml.SpreadSheet.Data.CellRange(0, 0, 3, 3);
            GrapeCity.Xaml.SpreadSheet.Data.CellRange cellr2 = new GrapeCity.Xaml.SpreadSheet.Data.CellRange(4, 0, 2, 2);
            gcSpreadSheet1.Sheets[0].SelectionPolicy = GrapeCity.Xaml.SpreadSheet.Data.SelectionPolicy.MultiRange;
            //gcSpreadSheet1.Sheets[0].SetSelection(0, 0, 3, 3);
            gcSpreadSheet1.Sheets[0].SetSelection(cellr);
            //gcSpreadSheet1.Sheets[0].AddSelection(4, 0, 2, 2);
            //gcSpreadSheet1.Sheets[0].AddSelection(cellr2);
            gcSpreadSheet1.Sheets[0].AddSelection(cellr2, true);
            //gcSpreadSheet1.Sheets[0].AddSelection(4, 0, 2, 2, true);
            //Specifies the extent (or farthest cell) in the selection of cells.
            gcSpreadSheet1.Sheets[0].ExtendSelection(6, 3);                                 
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            GrapeCity.Xaml.SpreadSheet.Data.CellRange cellr3 = new GrapeCity.Xaml.SpreadSheet.Data.CellRange(0, 0, 3, 3);
            listBox1.Items.Add(gcSpreadSheet1.Sheets[0].IsAnyCellInColumnSelected(0).ToString());
            listBox1.Items.Add(gcSpreadSheet1.Sheets[0].IsAnyCellInRowSelected(10).ToString());
            listBox1.Items.Add(gcSpreadSheet1.Sheets[0].IsSelected(3, 3).ToString());
            //gcSpreadSheet1.Sheets[0].ClearSelections();
            //gcSpreadSheet1.Sheets[0].ClearSelection(0, 0, 3, 3);
            //gcSpreadSheet1.Sheets[0].ClearSelection(cellr3);          
        }

VB
Copy Code

Private Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
        Dim cellr As New GrapeCity.Xaml.SpreadSheet.Data.CellRange(0, 0, 3, 3)
        Dim cellr2 As New GrapeCity.Xaml.SpreadSheet.Data.CellRange(4, 0, 2, 2)
        GcSpreadSheet1.Sheets(0).SelectionPolicy = GrapeCity.Xaml.SpreadSheet.Data.SelectionPolicy.MultiRange
        'GcSpreadSheet1.Sheets(0).SetSelection(0, 0, 3, 3)
        GcSpreadSheet1.Sheets(0).SetSelection(cellr)
        'GcSpreadSheet1.Sheets(0).AddSelection(4, 0, 2, 2)
        'GcSpreadSheet1.Sheets(0).AddSelection(cellr2)
        GcSpreadSheet1.Sheets(0).AddSelection(cellr2, True)
        'GcSpreadSheet1.Sheets(0).AddSelection(4, 0, 2, 2, True)
        'Specifies the extent (or farthest cell) in the selection of cells.
        GcSpreadSheet1.Sheets(0).ExtendSelection(6, 3)
               
    End Sub

    Private Sub Button_Click_1(sender As Object, e As RoutedEventArgs)
        Dim cellr3 As New GrapeCity.Xaml.SpreadSheet.Data.CellRange(0, 0, 3, 3)
        ListBox1.Items.Add(GcSpreadSheet1.Sheets(0).IsAnyCellInColumnSelected(0).ToString())
        ListBox1.Items.Add(GcSpreadSheet1.Sheets(0).IsAnyCellInRowSelected(10).ToString())
        ListBox1.Items.Add(GcSpreadSheet1.Sheets(0).IsSelected(3, 3).ToString())
        'GcSpreadSheet1.Sheets(0).ClearSelections()
        'GcSpreadSheet1.Sheets(0).ClearSelection(0, 0, 3, 3)
        'GcSpreadSheet1.Sheets(0).ClearSelection(cellr3)
    End Sub

See Also