Xtrareport Cross-table adaptive row height and optimal column width

Source: Internet
Author: User

1. The line height of the adaptive wardrobe, bind the Customrowheight event, the code is as follows:

Private Graphics gr = Graphics.fromhwnd (IntPtr.Zero);

private void Pivotgrid1_customrowheight (object sender, HuanSi.XtraReports.UI.PivotGrid.PivotCustomRowHeightEventArgs e) {

E.rowheight = 20;

var grid=sender as HuanSi.XtraReports.UI.XRPivotGrid;

var List=e.data.getfieldsbyarea (HuanSi.XtraPivotGrid.PivotArea.RowArea, false);

foreach (var item in list)

{

var obj=grid. GetFieldValue (item, E.rowindex);

if (obj = = null)

Continue

var font = (item as HuanSi.XtraReports.UI.PivotGrid.XRPivotGridField). Appearance.Cell.Font;

SizeF size = gr. MeasureString (obj. ToString (), font, item. Width);

int height = Convert.ToInt32 (math.ceiling (size). Height));

E.rowheight = e.rowheight > height? E.rowheight:height;

}

}

As follows:

2. The line height of the adaptive data is also bound to the Customrowheight event, the code is as follows:

Private Graphics gr = Graphics.fromhwnd (IntPtr.Zero);

private void Xrpivotgrid1_customrowheight_1 (object sender, Pivotcustomrowheighteventargs e) {

e.rowheight = 0;

for (int i = 0; I <= e.columncount-1; i++) {

String value = E.getrowcellvalue (i). ToString ();

SizeF size = gr. MeasureString (value, E.datafield.appearance.cell.font, e.datafield.width);

int height = Convert.ToInt32 (math.ceiling (size). Height));

E.rowheight = e.rowheight > height? E.rowheight:height;

}

}

Misappropriation of one online:

3. Adaptive column widths

The adaptive column width is extremely simple, the binding BeforePrint event can be, the code is as follows:

private void Pivotgrid1_beforeprint (object sender, System.Drawing.Printing.PrintEventArgs e) {

var grid=sender as HuanSi.XtraReports.UI.XRPivotGrid;

Grid. Bestfit ();

}

Re-misappropriation of a DX official:

Xtrareport Cross-table adaptive row height and optimal column width

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.