以编程方式创建表

发布于 2024-11-30 09:45:36 字数 1650 浏览 1 评论 0原文

我正在开发 devexreport,我想以编程方式创建一个表,我使用这些代码,但有一点问题。

        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 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.

The table result is like this

What is wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨落成白 2024-12-07 09:45:36

不确定它是否有帮助,但尝试移动 tbl.Rows.Add(row); 部分,如下所示:

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);
}

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文