开发者论坛

 找回密码
 注册 (请使用非IE浏览器)
查看: 1806|回复: 0

XRTable如何实现自适应列宽

[复制链接]

0

精华

0

贡献

0

赞扬

帖子
5
软币
101
在线时间
4 小时
注册时间
2019-7-30
发表于 2019-8-1 08:40:06 | 显示全部楼层 |阅读模式
本帖最后由 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()一样的效果。


回复

使用道具 举报

Archiver|手机版|小黑屋|开发者网 ( 苏ICP备08004430号-2 )
版权所有:南京韵文教育信息咨询有限公司

GMT+8, 2024-4-26 20:18

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表