devexpress-gridControl添加列
devexpress控件这个大家都很陌生,楼主在做这次项目的时候,全部使用的都是devexpress这个控件,这个控件大家也可以了解下,皮肤什么的都有,控件也很美观,今天就说下gridContro如何添加一行数据。devexpress中的gridControl就相当于dataGridView
代码如下:
/// <summary>
/// 设置Grid的每一列
/// </summary>
private void GridColumnBind()
{
try
{
GridColumn gc = new GridColumn();
gc.Caption = "公告类型";
gc.FieldName = "AnnouncType";
gc.Visible = true;
gc.VisibleIndex = 1;
this.gridView2.Columns.Add(gc);
gc = new GridColumn();
gc.Caption = "是否删除";
gc.FieldName = "IsDel";
gc.Visible = false;
this.gridView2.Columns.Add(gc);
gc = new GridColumn();
gc.Caption = "公告内容";
gc.FieldName = "AnnouncContent";
gc.Visible = true;
gc.VisibleIndex = 2;
this.gridView2.Columns.Add(gc);
gc = new GridColumn();
gc.Caption = "公告时间";
gc.FieldName = "AnnouncTime";
gc.Visible = true;
gc.VisibleIndex = 3;
this.gridView2.Columns.Add(gc);
gc = new GridColumn();
gc.Caption = "GUID编号";
gc.FieldName = "GUID";
gc.Visible = false;
this.gridView2.Columns.Add(gc);
////单元格内容左对齐
//DevExpress.XtraGrid.Columns.GridColumn col = gridView2.Columns;
DevExpress.XtraGrid.Columns.GridColumn col1 = gridView2.Columns;
//col.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
col1.AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
}
catch (Exception ex)
{
log4net.ILog log = log4net.LogManager.GetLogger(this.GetType());
log.Debug("错误信息:方法(GridColumnBind)" + ex.Message.ToString());
}
}
单元格内容左对齐:想对齐哪一列 就把索引写进去 ,log4net如果没有可以删除
页:
[1]