Managing Cell Controls in Columns

Accessing Cell Controls

To access and modify an existing cell control in the column, developers can use the CellControl property of a Aspose.Cells.GridDesktop.Data.GridColumn. Once a cell control is accessed, developers can modify its properties at runtime. For an instance, in the example given below, we have accessed an existing CheckBox cell control from a specific Aspose.Cells.GridDesktop.Data.GridColumn and modified its Checked property.

IMPORTANT: CellControl property provides a cell control in the form of CellControl object. So, if you need to access a specific type of cell control, say CheckBox then you will have to typecast the CellControl object to CheckBox class.

// 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();
// Accessing cell control in the column and typecasting it to CheckBox
Aspose.Cells.GridDesktop.CheckBox cb = (Aspose.Cells.GridDesktop.CheckBox)sheet.Columns[2].CellControl;
if (cb != null)
{
// Modifying the Checked property of CheckBox
cb.Checked = true;
}
else
{
MessageBox.Show("Please add control before accessing it.");
}

Removing Cell Controls

To remove an existing cell control, developers can simply access a desired worksheet and then Remove the cell control from the specific column by using the RemoveCellControl method of Aspose.Cells.GridDesktop.Data.GridColumn.

// 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();
// Removing cell control from the column
sheet.Columns[2].RemoveCellControl();