Adding Cell Controls in Columns

Introduction

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.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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");

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. 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.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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();

Above code snippet adds checkboxes to all cells of the specified column. 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// 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);

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. For more information about the event handling of comboboxes, please refer to the Event Handling of a ComboBox Control.