XRTable無法完成自適應列寬
				
					 
					
					
					
						發表于2019-07-29
						回復:1
						查看:6953  |  
					
				 
				
					最近項目中用到XtraReport,發現XRTable無法完成自適應列寬。在XRTable的BeginInit()方法和EndInit()方法之間調用AdjustSize()方法,發現可以實現自適應高度,但是無法實現自適應寬度。以下是測試代碼:
public XRTable CreateXRTable()
{
    XRTable xt = new XRTable();
    xt.LocationF = new PointF(0, 0);
    xt.Borders = DevExpress.XtraPrinting.BorderSide.All;
    xt.BeginInit();
    xt.HeightF = 300F;
    float TotalWidth = this.PageWidth - this.Margins.Left - this.Margins.Right;
    for (int i = 0; i < 4; i++)
    {
        XRTableRow xrow = new XRTableRow();
        xrow.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleCenter;
        for (int j = 0; j < 3; j++)
        {
            XRTableCell xc = new XRTableCell();
            xc.CanGrow = true;
            //xc.CanShrink = false;
            if(j == 0)
            {
                //xc.Weight = 0.4;
                xc.Text = "Hello World Hello World Hello World Hello World Hello World Hello World Hello World Hello World" + j;
            }
            else if(j == 1)
            {
                //xc.Weight = 0.3;
                xc.Text = "Hello World Hello World Hello World" + j;
            }
            else
            {
                //xc.Weight = 0.3;
                xc.Text = "Hello World Hello World" + j;
            }
            xrow.Cells.Add(xc);
        }
        xt.Rows.Add(xrow);
    }
    xt.AdjustSize();
    xt.EndInit();
    xt.WidthF = TotalWidth;
    return xt;
}
					
					
											
					
									 
				
			 
			
登錄 慧都網發表評論