管理列中的 Cell 控件

访问 Cell 控件

要访问和修改列中现有的单元格控件,开发人员可以使用Aspose.Cells.GridDesktop.Data.GridColumn.访问单元格控件后,开发人员可以在运行时修改其属性。例如,在下面给出的示例中,我们访问了一个现有的复选框来自特定的细胞控制Aspose.Cells.GridDesktop.Data.GridColumn并修改了它的 Checked 属性。

重要的: CellControl 属性以以下形式提供单元格控件细胞控制目的。所以,如果你需要访问特定类型的单元格控件,比如说复选框那么你将不得不强制转换细胞控制反对复选框班级。

// 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.");
}

删除 Cell 控件

要删除现有的单元格控件,开发人员可以简单地访问所需的工作表,然后去掉通过使用特定列的单元格控件删除单元格控件的方法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();