zoukankan      html  css  js  c++  java
  • XtraReport三动态数据绑定

    代码还用上一节的,把Report的Datasource去掉。各个绑定的字段也去掉,有了第二节的基础,现在看这个就不难了,无非就是传到report一个数据集,在把这个数据集绑定到各控件里 清空details里的Cell的值,各cell改成数据库对应列的名字方便绑定

    XReport 代码如下 作用就是绑定一下数据

      XREPORT代码在设计器界面右键显示

      public XtraReport1(DataTable dt)
            {
                InitializeComponent();
                this.DataSource = dt;
                //这里面的Text是xrtable的属性 区分大小写
                this.xrTableCell1.DataBindings.Add("Text",dt,"bid");
                this.xrTableCell2.DataBindings.Add("Text", dt, "bname");
                this.xrTableCell3.DataBindings.Add("Text", dt, "shuoming");
                this.xrTableCell4.Text = "编号";
                this.xrTableCell5.Text = "名称";
                this.xrTableCell6.Text = "备注";
                
            }

    Form1代码如下

       private void button1_Click(object sender, EventArgs e)
            {
                DataTable dt = new DataTable();
                string constr = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=pwd1";
                SqlConnection con = new SqlConnection(constr);
                try
                {
                    con.Open();
                    SqlCommand com = new SqlCommand("select bid,bname,shuoming from book",con);
                    SqlDataAdapter dpt = new SqlDataAdapter(com);
                    dpt.Fill(dt);
                    XtraReport1 report = new XtraReport1(dt);
                    report.Landscape = true;
                    documentViewer1.DocumentSource = report;
                    report.CreateDocument();
                }
                catch (Exception)
                {
                    
                    throw;
                }
            }

    理解:

          只有在datalis下面才能显示多行数据,Reportheader只是报表的头部。

      Xrtable  建立在datalis下面,form 下添加控件有splitcontrol 作为容器 dock属性为fill ,documentview 属性dock=fill, navbarcontrol 导航窗体,FORM1属性 windowsstate 设置max最大化

  • 相关阅读:
    自定义的弹出框列表适配器,类似于大众点评或美团
    Android 微信支付&支付宝支付
    动态设置 view 在布局中位置
    android 之图片异步加载
    android 侧滑菜单
    Google 官方 侧滑 drawerlayout
    python D27网络传输协议
    计算机单位换算、以及sort、sorted函数的区别
    python D26 socket、网络整个通信流程
    python D25 包
  • 原文地址:https://www.cnblogs.com/xiaowie/p/8970709.html
Copyright © 2011-2022 走看看