管理列中的单元格控件

访问单元格控件

要访问并修改列中的现有单元格控件,开发人员可以使用Aspose.Cells.GridDesktop.Data.GridColumn的CellControl属性。一旦访问了单元格控件,开发人员就可以在运行时修改它的属性。例如,在下面的示例中,我们已经访问了特定Aspose.Cells.GridDesktop.Data.GridColumn中现有的复选框单元格控件,并修改了其Checked属性。

重要: CellControl 属性以CellControl对象的形式提供单元格控件。因此,如果您需要访问特定类型的单元格控件,比如复选框,那么您需要将CellControl对象转换为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();
// 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.");
}

删除单元格控件

要移除现有的单元格控件,开发人员可以简单地访问所需的工作表,然后使用Aspose.Cells.GridDesktop.Data.GridColumnRemoveCellControl方法从特定列中移除单元格控件。

// 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();