• XtraReport交叉表自适应行高及最佳列宽


    1.自适应行头的行高,绑定CustomRowHeight事件,代码如下:

    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;

    }

    }

    效果图如下:

    clip_image001

    2.自适应数据的行高,同样绑定CustomRowHeight事件,代码如下:

    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;

    }

    }

    盗用网上一张效果图:

    clip_image002

    3.自适应列宽

    自适应列宽则极其简单,绑定BeforePrint事件即可,代码如下:

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

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

    grid.BestFit();

    }

    再次盗用DX官方的一张效果图:

    clip_image003

  • 相关阅读:
    c++ 有序二叉树的应用
    c++ 二叉树的遍历
    c++ 创建二叉树
    c++ 双向链表 的查找和删除
    c++ 双向循环链表
    c++ 双向链表
    Jzoj4209 已经没有什么好害怕的了
    Jzoj4209 已经没有什么好害怕的了
    后缀自动机转后缀树模板
    后缀自动机转后缀树模板
  • 原文地址:https://www.cnblogs.com/wanglj2007/p/5503091.html
Copyright © 2020-2023  润新知