Skip to main content

Selecting Cells

  • 4 minutes to read

This section deals with selecting cells programmatically. Focused and selected records are discussed in the Focused/Selected Records and Selecting Records topics.

The View’s OptionsSelection.CellMultiSelect property allows you to select/deselect particular cells within the current (Banded) Table View’s record selection. If this property is set to False, only entire record(s) (row(s) in a (Banded) Table View) can be selected. Setting this property also affects the View’s OptionsSelection.MultiSelect property’s value. The OptionsSelection.MultiSelect property’s value is automatically set to the value passed to the OptionsSelection.CellMultiSelect property. A column is called “selected” whenever it has at least one selected cell within the View’s record selection.

When the View’s OptionsSelection.CellMultiSelect property is set to True, the record selection can be adjusted according to your needs by including/excluding particular columns (i.e. their cells) from the selection.

The most obvious solution for selecting/deselecting a specific column’s cells within the record selection is to assign the corresponding value to the column’s Selected property as shown in the following code example.

tvFilms.Columns[0].Selected := True;

Note

When the View’s OptionsSelection.CellMultiSelect property is set to True, the entire record selection can be easily performed by means of the indicator (set the View’s OptionsView.Indicator property to True to make it visible).

If the View’s OptionsSelection.MultiSelect property is set to True, you are able to select multiple records at once. When this option is enabled and an end-user clicks any record, it becomes focused and selected at the same time. The focused record can be deselected by clicking it while pressing the Ctrl key. The same works for cell selection also, except that the Ctrl key does not deselect the cell or all of the specific column’s cells. Furthermore, when the View’s OptionsBehavior.PullFocusing property is set to True, the end-user can select records and cells by holding down the left mouse button and dragging the mouse pointer over the cells to be selected. This automatically focuses the records and cells under the cursor and adds them to the selection.

To select/deselect multiple cells, you can use one of the following methods:

The SelectColumns method selects a set of sequential columns which are in the column range specified by the parameters passed to the method. The following code example shows how to select the cells in the third, fourth and fifth columns, within the current record selection. The selection will contain only these columns’ cells and all other columns outside of the column range will be automatically deselected.

with tableView do
  Controller.SelectColumns(Columns[3], Columns[5]);

The SelectAllColumns method allows you to select the cells of all the columns within the current record selection, i.e. select all records.

Use this method to explicitly specify the cells that will be included in the selection which is designated by a column range and row range. The row range specifies a continuous range of records to be selected, while the column range specifies the columns to be selected. Two parameter pairs specify the starting and ending columns and row indexes of the required column and row ranges.

The following code selects rows 0-5 and columns 2-4 within the tableView View:

with tableView do
begin
  DataController.SelectRows(0, 5);
  Controller.SelectColumns(Columns[2], Columns[4]);
end;

Use this method to clear the current column (cell) selection within the View. Calling this method does not affect the current View’s record selection. Use the DataController.ClearSelection method instead.

To access the selected columns within the View, use the SelectedColumns method of the View’s controller.

See Also