Create table programmatically

泄露秘密 提交于 2019-12-12 12:26:02

问题


I am working on devexreport and I want to create a table programmatically I use these codes but have a little problem.

        DevExpress.XtraReports.UI.XRTable tbl = new XRTable();    
        DevExpress.XtraReports.UI.XRBarCode xrBarCode = new XRBarCode();

        Detail1.Controls.Add(tbl);

        tbl.Location = new System.Drawing.Point(358, 17);
        tbl.Size = new System.Drawing.Size(358, 50);
        tbl.Borders = (DevExpress.XtraPrinting.BorderSide)
            (((DevExpress.XtraPrinting.BorderSide.Left  
             | DevExpress.XtraPrinting.BorderSide.Top)
             | DevExpress.XtraPrinting.BorderSide.Right)
             | DevExpress.XtraPrinting.BorderSide.Bottom);


        // Total number of rows.
        int rowCnt;
        // Current row count.
        int rowCtr;
        // Total number of cells per row (columns).
        int cellCtr;
        // Current cell counter
        int cellCnt;

        rowCnt = int.Parse("2");
        cellCnt = int.Parse("3");

        for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
        {
            // Create new row and add it to the table.
            DevExpress.XtraReports.UI.XRTableRow row = new XRTableRow();
            tbl.Rows.Add(row);
            for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
            {
                // Create a new cell and add it to the row.
                DevExpress.XtraReports.UI.XRTableCell cell = new XRTableCell();
                cell.Text = "Row " + rowCtr + ", Cell " + cellCtr;
                row.Cells.Add(cell);
            }
        }

I try this code bur the last row is confused! all of the cels are on first cell.

What is wrong?


回答1:


Not sure if it will help, but try moving tbl.Rows.Add(row); part like this:

for (rowCtr = 1; rowCtr <= rowCnt; rowCtr++)
{
    // Create new row..
    DevExpress.XtraReports.UI.XRTableRow row = new XRTableRow();

    for (cellCtr = 1; cellCtr <= cellCnt; cellCtr++)
    {
        // Create a new cell and add it to the row.
        DevExpress.XtraReports.UI.XRTableCell cell = new XRTableCell();
        cell.Text = "Row " + rowCtr + ", Cell " + cellCtr;
        row.Cells.Add(cell);
    }

    // ..and add it to the table.
    tbl.Rows.Add(row);
}


来源:https://stackoverflow.com/questions/7109934/create-table-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!