Row Preview Sections 行预览部分

Goto Data Grid 数据网格

Row Preview Sections 行预览部分

Enable Preview Sections Enable Preview Sections(启用预览部分)

若要启用预览部分,请将 GridOptionsView.ShowPreview 属性设置为 true,并将数据字段分配给 GridView.PreviewFieldName 属性。

在这里插入图片描述

Text Offset 文本偏移

利用 GridView.PreviewIndent 属性设置预览部分中文本的左偏移量。
在这里插入图片描述

Fixed Preview Height Versus Auto Height 固定预览高度与自动高度

要限制预览部分的高度或允许这些部分根据内容动态调整自身,请使用 GridView.PreviewLineCount 和 GridOptionsView.AutoCalcPreviewLineCount 属性。

  • GridView.PreviewLineCount 等于 -1 或 0,则 GridOptionsView.AutoCalcPreviewLineCount 处于关闭状态预览部分占据一行,过多的文本将被剪切。
    在这里插入图片描述

  • GridView.PreviewLineCount 等于 -1 或 0,则 GridOptionsView.AutoCalcPreviewLineCount 处于开启状态文本已换行,每个预览部分将获得完全显示内容所需的行数。
    在这里插入图片描述

  • GridView.PreviewLineCount 等于正数,则 GridOptionsView.AutoCalcPreviewLineCount 处于关闭状态文本换行时,所有预览部分都会获得固定的行高。不适合这些部分的文本将被剪切。

在这里插入图片描述

  • GridView.PreviewLineCount 等于正数,则 GridOptionsView.AutoCalcPreviewLineCount 处于开启状态文本换行,预览区域根据其内容获得不同的高度。PreviewLineCount 属性值是允许的最大预览部分高度。如果特定预览部分中的内容需要更多空间,则会对其进行剪切。
    在这里插入图片描述

Custom Height 自定义高度

处理 GridView.MeasurePreviewHeight 事件,为特定预览部分设置单个高度。事件参数提供两个属性:

  • RowHeightEventArgs.RowHandle - 返回行句柄,允许您识别当前正在处理的行;
  • RowHeightEventArgs.RowHeight - 获取或设置当前行的预览部分的高度。

Custom Preview Content 自定义预览内容

要同时显示来自多个数据字段的自定义文本内容或值,请处理 GridView.CalcPreviewText 事件并在事件参数中设置 CalcPreviewTextEventArgs.PreviewText 属性。您还可以处理 GridView.CustomDrawRowPreview 事件以在预览部分中绘制图像。
在这里插入图片描述

//custom preview section text
private void gridView1_CalcPreviewText(object sender, DevExpress.XtraGrid.Views.Grid.CalcPreviewTextEventArgs e) {
    e.PreviewText = CalculateMyPreviewText(e.RowHandle);
}

private string CalculateMyPreviewText(int rowHandle) {
    DataRow row = gridView1.GetDataRow(rowHandle);
    string mpgcity = row["MPG City"].ToString();
    string mpghwy = row["MPG Highway"].ToString();
    string description = row["Description"].ToString();
    if (string.IsNullOrEmpty(description))
        return string.Empty;
    return string.Format("MPG City: {0}, MPG Highway: {1}\n{2}", mpgcity, mpghwy, description);
}

//preview section image
private void gridView1_CustomDrawRowPreview(object sender, DevExpress.XtraGrid.Views.Base.RowObjectCustomDrawEventArgs e) {
    Bitmap image = GetRowImage(e.RowHandle);
    e.Cache.DrawImage(image, e.Bounds.X, e.Bounds.Y, image.Width, image.Height);
    Point textOrigin = new Point(e.Bounds.X + image.Width + 20, e.Bounds.Y + 4);
    Rectangle textRect = new Rectangle(textOrigin.X, textOrigin.Y, e.Bounds.Width - textOrigin.X, e.Bounds.Height - 8);
    string text = CalculateMyPreviewText(e.RowHandle);
    StringFormat format = e.Appearance.GetStringFormat();
    format.Trimming = StringTrimming.EllipsisWord;
    e.Cache.DrawString(text, e.Appearance.Font, e.Appearance.GetForeBrush(e.Cache), textRect, format);
    e.Handled = true;
}

private Bitmap GetRowImage(int rowHandle) {
    DataRow row = gridView1.GetDataRow(rowHandle);
    if (row["Image"] == System.DBNull.Value)
        return null;
    byte[] imageData = (byte[])row["Image"];
    return new Bitmap(new System.IO.MemoryStream(imageData));
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值