Enabling and Configuring Selection
Send Feedback

Glossary Item Box

Topic Overview

Purpose

This topic provides a conceptual overview, with code, on enabling and configuring the selection of cells and rows on the IGGridView™ control.

Required background

The following table lists the topics required as a prerequisite to understanding this topic.

Topic

Purpose

Adding the Grid Framework File

This topic explains the requirements for adding the grid framework file to an Xcode project; a requirement for using the IGGridView™ control .


In this topic


Introduction

Selection summary

The IGGridView has two types of selection, cell and row. To switch between these modes, use the IGGridView’s selectionType property, which can be, set to any of the following values:

  • IGGridViewSelectionTypeRow – when you press a cell the row is selected.
  • IGGridViewSelectionTypeCell – when you press a cell the cell is selected.
  • IGGridViewSelectionTypeNone – when you press a cell nothing is selected.

Determining selection

By default, only one cell or row can be selected, if you want multiple selections, set the IGGridView’s allowMultipleSelection property to YES. To determine which cells and rows are selected, there are a couple of methods for each type of selection.

Selection

Methods

Cells

  • pathForSelectedCell – top most selected cell.
  • pathsForSelectedCells – all selected cells.

Rows

  • pathForSelectedRow – top most selected row.
  • pathsForSelectedRows – all selected rows.

Cell and row selection

To select a row or cell, there is one method each:

  • -(void)selectRowAtPath:(IGRowPath*)path animated:(BOOL)animated scrollPosition:(IGGridViewScrollPosition)scrollPosition;
  • -(void)selectCellAtPath:(IGCellPath*)path animated:(BOOL)animated scrollPosition:(IGGridViewScrollPosition)scrollPosition;

Cells or rows that are selected using these methods are scrolled to automatically. To disable scrolling, pass IGGridViewScrollPositionNone as the scrollPosition parameter. Multiple selections are honored with the selection methods. If multiple selections are disabled, you can select a new cell or row using the method, and the previously selected cell or row will automatically be deselected. Likewise, if multiple selections are on, then multiple cells or rows would be selected.

To remove selection for cells and rows, the following methods exist on the IGGridView:

  • -(void)deselectCellAtPath:(IGCellPath*)path animated:(BOOL)animated;
  • -(void)deselectRowAtPath:(IGRowPath*)path animated:(BOOL)animated;

To clear all selected cells or rows the following method can be used:

  • -(void)deselectAll;
Note: Delegate methods will not be raised when selection and deselecting methods are called.

The following IGGridViewDelegate methods will fire before a cell or row is selected or deselected. To cancel the selection or deselecting, return nil. To change the selection, return an alternate path.

  • -(IGRowPath*)gridView:(IGGridView*)gridView willSelectRowAtPath:(IGRowPath*)path;
  • -(IGCellPath*)gridView:(IGGridView*)gridView willSelectCellAtPath:(IGCellPath*)path;
  • -(IGRowPath*)gridView:(IGGridView*)gridView willDeselectRowAtPath:(IGRowPath*)path;
  • -(IGCellPath*)gridView:(IGGridView*)gridView willDeselectCellAtPath:(IGCellPath*)path;

The following delegate methods will fire after a cell or row is selected or deselected. These methods are not cancellable.

  • -(void)gridView:(IGGridView*)gridView didSelectRowAtPath:(IGRowPath*)path;
  • -(void)gridView:(IGGridView*)gridView didSelectCellAtPath:(IGCellPath*)path;
  • -(void)gridView:(IGGridView*)gridView didDeselectRowAtPath:(IGRowPath*)path;
  • -(void)gridView:(IGGridView*)gridView didDeselectCellAtPath:(IGCellPath*)path;

When a cell is selected, it is possible to change the color or display a custom view overtop of the cell by using the selectedColor and selectedView properties of the IGGridViewCell. The best place to set these properties is when you create the cell, or when the cell is initialized, which you can detect with the following IGGridViewDelegate method.

  • -(void)gridView:(IGGridView*)gridView initializeCell:(IGGridViewCell*)cell;

Changing the Color of a Selected Cell – Code Example

Description

The following code demonstrates the handling of the initializeCell method found on the IGGridViewDelegate protocol, to change the background color and view of a selected cell to indicate the selection by including a checkmark.

Code

In Objective-C:

-(void)gridView:(IGGridView *)gridView initializeCell:(IGGridViewCell *)cell { cell.selectedColor = [UIColor clearColor]; UIView* v = [[UIView alloc]init]; v.backgroundColor = [UIColor blackColor]; v.alpha = .4;

cell.selectedView = v; }

In C#:

public override void InitializeCell (IGGridView gridView, IGGridViewCell cell)
{
   cell.SelectedColor = UIColor.Clear;

   UIView v = new UIView();
   v.BackgroundColor = UIColor.Black;
   v.Alpha = .4f;

   cell.SelectedView = v;
}


Related Content

Topics

The following topics provide additional information related to this topic.

Topic

Purpose

This topic provides basic information about creating an instance of the IGGridView and displaying data to help you with getting up and running with using the control.

This section serves as an introduction to the IGGridView’s key features and functionalities.