2011-08-18 3 views
3

Je travaille sur devexreport et je veux créer une table par programmation J'utilise ces codes mais j'ai un petit problème.Créer une table par programmation

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

J'ai essayé ce code et la dernière rangée est confuse! toutes les cellules sont sur la première cellule.

The table result is like this

Quel est le problème?

Répondre

3

Je ne sais pas si cela va aider, mais essayez de déplacer une partie tbl.Rows.Add(row); comme ceci:

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

Merci aidé assez .. – Rapunzo

Questions connexes