XRTable如何实现自适应列宽
本帖最后由 ZZSZZ0805 于 2019-8-1 08:42 编辑最近项目中用到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;
}
想实现交叉表XRPivotGrid的BestFit()一样的效果。
页:
[1]