在列中添加单元格控件

介绍

目前,Aspose.Cells.GridDesktop支持添加三种类型的单元格控件,包括如下:

  • 按钮
  • 复选框
  • 组合框

所有这些控件都是继承自抽象类CellControl

重要: 如果要将单元格控件添加到单个单元格而不是整个列,则可以参考在工作表中添加单元格控件。

添加按钮

要在Aspose.Cells.GridDesktop中的列中添加按钮,请按照以下步骤操作:

  • 向您的表单中添加Aspose.Cells.GridDesktop控件
  • 访问任何所需的工作表
  • 按钮添加到工作表的任何指定

注意: 在添加按钮时,我们可以指定按钮的宽度、高度和标题。

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

上述代码片段将按钮添加到所指定列的所有单元格中。每当选择特定列的任何单元格时,按钮会变为可见。有关按钮事件处理的更多信息,请参阅按钮控件的事件处理。

添加复选框

要在Aspose.Cells.GridDesktop中的列中添加复选框,请按照以下步骤操作:

  • 向您的表单中添加Aspose.Cells.GridDesktop控件
  • 访问任何所需的工作表
  • 工作表的任何指定中添加复选框

注意: 在添加复选框时,我们还可以指定复选框的状态。

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

上面的代码片段将复选框添加到指定列的所有单元格。有关复选框的事件处理的更多信息,请参阅复选框控件的事件处理。

添加下拉列表框

要使用Aspose.Cells.GridDesktop在列中添加组合框,请按照以下步骤进行:

  • 向您的表单中添加Aspose.Cells.GridDesktop控件
  • 访问任何所需的工作表
  • 创建一个将添加到组合框的项目(或值)数组
  • 工作表的任何指定中添加包含项目或值的组合框
// 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);

上面的代码片段将组合框添加到指定列的所有单元格。每当选择特定列的任何单元格时,组合框都会变为可见。有关组合框的事件处理的更多信息,请参阅组合框控件的事件处理。