Dev GridControl详解(一)控件层次和数据绑定

本来想写GridControl的文章,发现网上已经有系统的讲解了,直接粘过来,C博找不到转载按钮我也是醉了我。

感谢nanchuan以及nanchuan文章的原作者。我会在你们的基础上随时补充。

以下【转载】:

使用时拖拽过来,如下所示即使拖拽过来原封不动的样子:




绑定数据源 在程序中写入构建一个表格的代码:

private DataTable InitDt()  
   {  
       DataTable dt = new DataTable("个人简历");  
       dt.Columns.Add("id",typeof(int));  
       dt.Columns.Add("name", typeof(string));  
       dt.Columns.Add("sex", typeof(int));  
       dt.Columns.Add("address", typeof(string));  
       dt.Columns.Add("aihao", typeof(string));  
       dt.Columns.Add("photo", typeof(string));  
       dt.Rows.Add(new object[] { 1, "张三", 1, "东大街6号", "看书", "" });  
       dt.Rows.Add(new object[] { 1, "王五", 0, "西大街2号", "上网,游戏", "" });  
       dt.Rows.Add(new object[] { 1, "李四", 1, "南大街3号", "上网,逛街", "" });  
       dt.Rows.Add(new object[] { 1, "钱八", 0, "北大街5号", "上网,逛街,看书,游戏", "" });  
       dt.Rows.Add(new object[] { 1, "赵九", 1, "中大街1号", "看书,逛街,游戏", "" });  
       return dt;  
   }  
绑定数据代码:

private void BindDataSource(DataTable dt)  
   {  
       //绑定DataTable  
       gridControl1.DataSource = dt;  
   }  
private void BindDataSource(DataSet ds)
{
    //绑定DataSet
    gridControl1.DataSource = ds;
    gridControl1.DataMember = "表名"; 
}
class Model 
{
public string col1 {get;set;}
public string col2 {get;set;}
}

private void BindDataSource(List<Model>   lst)
{
    //绑定List
    gridControl1.DataSource = lst; 
}




下面代码是常见的GridControl代码,可以帮助理解GridControl层次关系:

            this.gridcontrol.MainView = this.gridView;//这里
            this.gridcontrol.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
            this.repositoryItemCheckEdit1});
            this.gridcontrol.ViewCollection.AddRange(new DevExpress.XtraGrid.Views.Base.BaseView[] {
            this.gridView);
    
            this.gridView.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
            this.gridColumn1,
            this.gridColumn2});//这里
            this.gridView.GridControl = this.gridcontrol;//还有这里
            this.gridView.Name = "gridView";
            this.gridView.OptionsView.ShowColumnHeaders = false;
            this.gridView.OptionsView.ShowGroupPanel = false;
            this.gridView.OptionsView.ShowIndicator = false;
           
            this.gridColumn1.Caption = "gridColumn1";
            this.gridColumn1.ColumnEdit = this.repositoryItemCheckEdit1;
            this.gridColumn1.FieldName = "Checked";
            this.gridColumn1.Name = "gridColumn1";
            this.gridColumn1.Visible = true;
            this.gridColumn1.VisibleIndex = 0;
            this.gridColumn1.Width = 20;



  • 6
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值