星空网 > 软件开发 > ASP.net

GridControl 绑定非绑定列

1、设置非绑定列的FieldName;

2、修改 UnboundType 属性,除默认的bound外均可(但是如果不是Boolean类型的选Boolean,只会显示一个勾选框,不会显示内容)

  GridControl 绑定非绑定列

  GridControl 绑定非绑定列

3、绑定 gridView 的 CustomUnboundColumnData 事件

  GridControl 绑定非绑定列

4、最后在 CustomUnboundColumnData 事件中实现非绑定列的绑定,代码如下:

private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e){  if (e.Column.FieldName == "列名" && e.IsGetData) 
  {
    e.Value = 值
  }
}

 

下面是示例代码:

    
     //为非绑定列 colAB 设置一个窗体内全局唯一的FieldName
     string colClassAndCount = "ClassAndCount"; //创建测试数据表 public static class ServiceData { public static DataTable GetClassCount() { DataTable dt = new DataTable(); dt.Columns.Add("class", typeof(string)); //年级 dt.Columns.Add("count", typeof(int)); //人数 dt.Rows.Add("一年级", 120); dt.Rows.Add("二年级", 180); dt.Rows.Add("三年级", 890); dt.Rows.Add("四年级", 108); dt.Rows.Add("五年级", 280); dt.Rows.Add("六年级", 320); dt.Rows.Add("七年级", 450); dt.Rows.Add("八年级", 410); dt.Rows.Add("九年级", 230); return dt; } } //绑定非绑定列 private void gridView_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e) { DataView dv = ServiceData.GetClassCount().DefaultView; if (e.IsGetData) { //设置非绑定列的FieldName为定义的全局FieldName, //匹配 gridView 每一列的FieldName //设置非绑定列 colAB 显示内容:Class + Count if (e.Column.FieldName == colClassAndCount) { string classNo = dv[e.ListSourceRowIndex]["class"].ToString(); string countNum = dv[e.ListSourceRowIndex]["count"].ToString(); string ClassAndCount = classNo + " + " + countNum; e.Value = ClassAndCount; } } } private void Form5_Load(object sender, EventArgs e) { gridControl3.DataSource = ServiceData.GetClassCount(); }

 最终结果如下: 

  GridControl 绑定非绑定列

 




原标题:GridControl 绑定非绑定列

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流