Xtrareport multi-column report

First look at the layout designer

detail:

  Grouping must use GroupHeather

 

After setting, it will appear on the right

 

 Next is the code part

 

  Code in Form1

  

using DevExpress.XtraReports.UI;

  private DataSet getds()
        {

            DataSet ds = new DataSet();
            string constr = "server=192.168.100.222;user=sa;pwd=p@ssw1rd;database=pwd1";
            SqlConnection mycon = new SqlConnection(constr);

            try
            {
                mycon.Open();
                SqlCommand mycom = new SqlCommand("select * from mulittb", mycon);
                SqlDataAdapter dpt = new SqlDataAdapter(mycom);
                dpt.Fill(ds, "mulittb");
                mycon.Close();


            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }

            return ds;
        }
        //显示
        private void simpleButton1_Click(object sender, EventArgs e)
        {
            DataSet ds = getds();
            XtraReport1 report = new XtraReport1(ds);
            report.Landscape = true;
            documentViewer1.DocumentSource = report;
            report.CreateDocument();
        }
        //预览
        private void simpleButton2_Click(object sender, EventArgs e)
        {
            DataSet ds = getds();
            XtraReport1 report = new XtraReport1(ds);
            report.Landscape = true;
            report.ShowPreviewDialog();
        }

Xtrareport code

  

   public XtraReport1(DataSet ds)
        {
            InitializeComponent();
            this.DataSource = ds;
            this.DataMember = "mulittb";
            xrTableCell1.DataBindings.Add( " Text " ,ds, " type " );
             // Set the groupHeader group field (type , report column sorting type. Asc) can not write 
            GroupField fz = new GroupField( " type " ,XRColumnSortOrder.Ascending );
             // Add group fields to GroupHeader1 ((GroupHeaderBand 
            )( this .FindControl( " GroupHeader1 " , true ))).GroupFields.Add(fz);
             // Bind fields that display multiple columns 
            this .xrTableCell2.DataBindings. Add( " Text",ds,"name");

        }

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325260243&siteId=291194637