在 DevExpress xtra 报告中,我想动态增加 table 的高度

In DevExpress xtra reports, I would like to increase height of table dynamically

在devexpress报告中,我有两个table。基于内容T2 table 高度增加,基于T1 高度应该设置。

我尝试在 BeforePrintAfterPrintSizeChangedTextChanged 事件 T2 以及 DataSourceChanged 事件中设置高度报道,如下,加图参考

T1.HeightF = T2.HeightF;

T1.SizeF = new SizeF(T1.WidthF, T2.HeightF);

但是上面的方法都不行。
知道如何动态设置 table 的高度吗?

您可以设置 XRControl.AnchorVertical property of your table to VerticalAnchorStyles.Both 值,这样您的 table 将始终附加到容器的两侧。

xrTable1.AnchorVertical = VerticalAnchorStyles.Both;

示例如下:

var source = new List<Tuple<string>>()
{
    new Tuple<string>("Text"),
    new Tuple<string>("Some\ntext"),
    new Tuple<string>("Some long long\nlong long long\nlong long long text.")
};

var cell = new XRTableCell();
cell.Text = "Just table";

var someCell = new XRTableCell();
someCell.Text = "Some text";

var anotherCell = new XRTableCell();
anotherCell.Text = "Another cell text";

var contentCell = new XRTableCell();
contentCell.DataBindings.Add(new XRBinding("Text", null, "Item1"));
contentCell.Multiline = true;

var anotherContentCell = new XRTableCell();
anotherContentCell.Text = "Content table";

var row = new XRTableRow();
row.Cells.AddRange(new[] { cell, someCell, anotherCell });

var contentRow = new XRTableRow();
contentRow.Cells.AddRange(new[] { contentCell, anotherContentCell });

var table = new XRTable();
table.Rows.Add(row);
table.Borders = DevExpress.XtraPrinting.BorderSide.All;
table.AnchorVertical = VerticalAnchorStyles.Both;

var contentTable = new XRTable();
contentTable.Rows.Add(contentRow);
contentTable.Borders = DevExpress.XtraPrinting.BorderSide.All;
contentTable.LeftF = 350F;

var panel = new XRPanel();
panel.HeightF = contentTable.HeightF = table.HeightF = 15F;
panel.WidthF = 650F;
panel.Controls.AddRange(new[] { table, contentTable });            

var detail = new DetailBand();
detail.HeightF = 30F;
detail.Controls.Add(panel);

var report = new XtraReport();
report.Bands.Add(detail);
report.DataSource = source;

report.ShowRibbonPreview();

示例结果如下: