【问题标题】:How to show image column in ultragrid?如何在超网格中显示图像列?
【发布时间】:2015-04-15 07:36:04
【问题描述】:

我有一个窗口形式的 Ultragrid,它通过数据表显示来自数据库的数据。 在数据表中我有一列包含图像路径我想知道如何让超网格显示这些路径的图像?

注意:我的 Infragistic 版本是 5.6,我正在使用 .net 2.0

【问题讨论】:

  • 使用 OnPaint / OnRender 事件并使用 System.Windows.Drawing 中的位图图像绘制图像。
  • 难道我不能告诉 Ultragrid 该列是图像,然后它使用该列中提供的图像路径以正确的格式显示它吗?
  • 你有什么样的数据你的数据源。是(二进制/流还是只是一个文件名)?
  • 我在问题中提到我在数据表中有一个包含图像路径的列。所以来源是文本(路径+文件名)(例如:C:\Users\msabry\FirstTask\1.jpg)

标签: c# winforms infragistics ultrawingrid


【解决方案1】:

您需要在 UltraGrid 中添加一个 Image 类型的未绑定列,并隐藏包含图像路径的列。为此,您可以像这样处理 InitializeLayout 事件:

private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
    // Hide the "path" column
    e.Layout.Bands[0].Columns["Path"].Hidden = true;

    // Add new unbound column of Image type - here you will show the pictures
    e.Layout.Bands[0].Columns.Add("Image").DataType = typeof(Image);
}

在您“准备好”您的网格以在 InitializwRow 事件中显示图片后,您可以像这样加载每个图像:

private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
{
    // Check if this is data row -  if you have summaries, groups...
    if (e.Row.IsDataRow)
    {
        // Create an image from the path string in the "Path" cell
        Image image = Bitmap.FromFile(e.Row.Cells["Path"].Text);

        // Put the image in the "Image" cell
        e.Row.Cells["Image"].Value = image;
    }
}

【讨论】:

  • 这正是我所做的,但我一直在寻找一种方法,使超网格可以理解路径列并将其直接显示为图像,而不是隐藏路径列并为实际图像创建另一个列。 +1 花时间写这个答案。
猜你喜欢
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-09
相关资源
最近更新 更多