查询 1
在第一行的第一列我想写一些硬编码的输入字符串
建议 1
可以使用单元格样式的 CellValue 属性设置特定单元格的单元格值。请参考以下代码,
this.gridControl1[1, 1].CellValue = "Sample";
建议 2
也可以使用单元格样式的Text属性来设置单元格值。请使用以下代码,
this.gridControl1[2, 1].Text = "Data";
建议 3
要为特定单元格设置单元格值,也可以使用 QueryCellInfo 事件。请参考以下代码,
//Event Triggering
this.gridControl1.QueryCellInfo += GridControl_QueryCellInfo;
//Event Customization
private void GridControl_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.RowIndex==1 && e.ColIndex==1)
{
e.Style.CellValue = "Sample Name";
}
if(e.RowIndex==2 && e.ColIndex==1)
{
e.Style.Text = "Sample ID";
}
}
查询 2
在第一行的第二列我要添加复选框
建议 1
要为特定单元格设置单元格类型为 CheckBox,可以使用 CellType 属性,并且可以使用 Description 属性设置 CheckBox 的名称。请参考以下代码,
this.gridControl1[1, 2].CellType = GridCellTypeName.CheckBox;
this.gridControl1[1, 2].Description = "CheckBox";
通过定义单元格的 CheckBoxOptions 属性,可以根据单元格的值选中或取消选中 CheckBox。
this.gridControl1[1, 2].CheckBoxOptions = new GridCheckBoxCellInfo("True","False","False",true);
this.gridControl1[1, 2].CellValue = "True";
建议 2
要将特定单元格的单元格类型设置为复选框,也可以使用 QueryCellInfo 事件。请参考以下代码,
//Event Triggering
this.gridControl1.QueryCellInfo += GridControl_QueryCellInfo;
//Event Customization
private void GridControl_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.RowIndex==2 && e.ColIndex==2)
{
e.Style.CellType = GridCellTypeName.CheckBox;
e.Style.Description = "CheckBox";
e.Style.CheckBoxOptions.CheckedValue = "True";
e.Style.CellValue="True";
}
}
Screenshot
Sample Link
UG Link
仪表板示例
\Syncfusion\EssentialStudio\\Windows\Grid.Windows\Samples\ Cell Types\Interactive Cell Demo\CS