当前位置: 代码迷 >> .NET报表 >> DevExpress中GridControl的重新绑定数据后怎么刷新
  详细解决方案

DevExpress中GridControl的重新绑定数据后怎么刷新

热度:518   发布时间:2016-05-05 01:39:04.0
DevExpress中GridControl的重新绑定数据后如何刷新?
DevExpress中GridControl的重新绑定数据后如何刷新?
第一次把gridControl1.DataSource = ds1.Tables["墒情信息表"];
然后显示一切正常

第二次gridControl1.DataSource = ds2.Tables["雨量信息表"];
这一次GridControl显示的列名还是之前墒情表的名称,请问如何刷新?????急啊!!!
------解决方案--------------------
你有没有一个事件来触发
你指的第二次绑定是在什么情况下出现的

一个按钮,还是一个方法,

如果是web程序
应该这样做
ViewState["datasource"]=ds1
如果第二次改你就这样
ViewState["datasource"]=ds2

然后在page_load
方法中
if(ViewState["datasource"]!=null)
{
grid.datasource=ViewState["datasource"] as DataSet;
}

就是用这样的方式,你改改

我们不管有几个数据源,只要有回传,或是执行事件都会经过page_load这样只要你更改了数据源,grid就会跟着变
------解决方案--------------------
你把你的代码放出来

包括load方法,看下,是不是哪里没写对
------解决方案--------------------
楼主没有办法,你就用两个panel吧,然后用两个控件,通过显示控制来实现两个数据源的显示
实在没有遇到这样的问题

------解决方案--------------------
楼主,今天看到贴差点就想说这事,觉得你很可能把列名定死了

哎,清空吧,这个必须的,要不看到的肯定是以前的嘛
------解决方案--------------------
        DataTable dt = null;
        DataTable dt1 = null;

        private void Form1_Load(object sender, EventArgs e)
        {
            DevExpress.XtraGrid.Columns.GridColumn colname = new DevExpress.XtraGrid.Columns.GridColumn();
            colname.Name = "colname";
            colname.FieldName = "colname";
            colname.VisibleIndex = 0;

            DevExpress.XtraGrid.Columns.GridColumn colpic = new DevExpress.XtraGrid.Columns.GridColumn();
            colpic.Name = "colpic";
            colpic.FieldName = "colpic";
            colpic.VisibleIndex = 1;

            DevExpress.XtraGrid.Columns.GridColumn colimg = new DevExpress.XtraGrid.Columns.GridColumn();
            colimg.Name = "colimage";
            colimg.FieldName = "colimage";
            colimg.VisibleIndex = 2;
            gridView1.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] { colname, colpic, colimg });

            //gridView1.OptionsView.RowAutoHeight = true;

            DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit picedit = new DevExpress.XtraEditors.Repository.RepositoryItemPictureEdit();
            picedit.AutoHeight = true;
            picedit.Name = "respositoryitempic1";
            colpic.ColumnEdit = picedit;
            DevExpress.XtraEditors.Repository.RepositoryItemImageEdit imageedit = new DevExpress.XtraEditors.Repository.RepositoryItemImageEdit();
            imageedit.AutoHeight = true;
            imageedit.Name = "respositoryitem1";
            colimg.ColumnEdit = imageedit;

            Image img = new Bitmap(@"G:\图片\无标题.jpg");

            dt = new DataTable();
            dt.Columns.Add("colname", typeof(string)).Caption="姓名";
            dt.Columns.Add("colpic", typeof(Image)).Caption="图像";
            dt.Columns.Add("colimage", typeof(Image)).Caption = "图像";

            dt.Rows.Add("asda", img, img);

            gridControl1.DataSource = dt;

            dt1 = new DataTable();
            dt1.Columns.Add("colname", typeof(string)).Caption = "aaa";
            dt1.Columns.Add("colpic", typeof(string)).Caption = "bbb";
  相关解决方案