| In our later discussions, we have discussed about adding and managing cell controls in worksheet. But, using those approaches, we can add cell controls to single cells one by one. What if someone would like to add cell controls to all cells of one or more columns? In such cases, to reduce the efforts of developers, Aspose.Cells.GridDesktop provides the feature of adding cell controls per column basis. It means that developers can only select a desired column and specify any cell control. The specified cell control will be added to all cells of the specified column. Let's see how can we use this feature. |
Adding Cell Controls in Columns
Currently, Aspose.Cells.GridDesktop support adding three types of cell controls, which include the following:
- Button
- CheckBox
- ComboBox
All of these controls are derived from an abstract class, CellControl.
IMPORTANT: If you want to add cell controls to a single cell instead of the whole column then you can refer to Adding Cell Controls in Worksheets.
Adding Button
To add buttons into a column using Aspose.Cells.GridDesktop, please follow the steps below:
- Add Aspose.Cells.GridDesktop control to your Form
- Access any desired Worksheet
- Add Button to any specified Column of the Worksheet
NOTE: While adding Button, we can specify the width, height and caption of the button.
Example:
//Accessing the worksheet of the Grid that is currently active Worksheet sheet = gridDesktop1.GetActiveWorksheet(); //Adding button to a specific column of the Worksheet sheet.Columns[2].AddButton(80, 20, "Hello");
'Accessing the worksheet of the Grid that is currently active
Dim sheet As Worksheet = gridDesktop1.GetActiveWorksheet()
'Adding button to a specific column of the Worksheet
sheet.Columns(2).AddButton(80, 20, "Hello")
Above code snippet adds buttons to all cells of the specified column. Whenever any cell of that specific column is selected, a button becomes visible as shown below in the figure:

Figure: Button column showing only a single button at the moment
For more information about the event handling of buttons, please refer to the Event Handling of a Button Control.
Adding CheckBox
To add checkboxes into a column using Aspose.Cells.GridDesktop, please follow the steps below:
- Add Aspose.Cells.GridDesktop control to your Form
- Access any desired Worksheet
- Add CheckBox to any specified Column of the Worksheet
NOTE: While adding CheckBox, we can also specify the state of the checkbox.
Example:
//Accessing the worksheet of the Grid that is currently active Worksheet sheet = gridDesktop1.GetActiveWorksheet(); //Adding checkbox to a specific column of the Worksheet sheet.Columns[2].AddCheckBox(true);
'Accessing the worksheet of the Grid that is currently active Dim sheet As Worksheet = gridDesktop1.GetActiveWorksheet() 'Adding checkbox to a specific column of the Worksheet sheet.Columns(2).AddCheckBox(True)
Above code snippet adds checkboxes to all cells of the specified column as shown below in the figure:

Figure: CheckBox column showing all checkboxes
For more information about the event handling of checkboxes, please refer to the Event Handling of a CheckBox Control.
Adding ComboBox
To add comboboxes into a column using Aspose.Cells.GridDesktop, please follow the steps below:
- Add Aspose.Cells.GridDesktop control to your Form
- Access any desired Worksheet
- Create an array of items (or values) that will be added to ComboBox
- Add ComboBox (containing items or values) to any specified Column of the Worksheet
Example:
//Accessing the worksheet of the Grid that is currently active Worksheet sheet = gridDesktop1.GetActiveWorksheet(); //Creating an array of items or values that will be added to combobox string[] items = new string[3]; items[0] = "Aspose"; items[1] = "Aspose.Grid"; items[2] = "Aspose.Grid.Desktop"; //Adding combobox (containing items) to a specific column of the Worksheet sheet.Columns[2].AddComboBox(items);
'Accessing the worksheet of the Grid that is currently active Dim sheet As Worksheet = gridDesktop1.GetActiveWorksheet() 'Creating an array of items or values that will be added to combobox Dim items() As String = New String(3) {} items(0) = "Aspose" items(1) = "Aspose.Grid" items(2) = "Aspose.Grid.Desktop" 'Adding combobox (containing items) to a specific column of the Worksheet sheet.Columns(2).AddComboBox(items)
Above code snippet adds comboboxes to all cells of the specified column. Whenever any cell of that specific column is selected, a combobox becomes visible as shown below in the figure:

Figure: ComboBox column showing only a single combobox at the moment
For more information about the event handling of comboboxes, please refer to the Event Handling of a ComboBox Control.

