使用Compact Framework在datagrid中显示图像

时间:2009-06-09 13:02:39

标签: compact-framework datagrid

是否可以在数据网格单元格中显示图像? 我目前正在使用紧凑型框架3.5。

有关于此的任何提示吗?

5 个答案:

答案 0 :(得分:9)

就像其他海报所评论的那样,你需要自己动手。幸运的是,这并不太难。

在我的应用程序中,我需要一种在特定列中绘制16x16图标的方法。我创建了一个继承自DataGridColumnStyle的新类,这样可以通过DataGrid对象轻松应用于DataGridTableStyle

class DataGridIconColumn : DataGridColumnStyle {

public Icon ColumnIcon {
    get;
    set;
}

protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight ) {

    // Fill in background color
    g.FillRectangle( backBrush, bounds );

    // Draw the appropriate icon
    if (this.ColumnIcon != null) {
        g.DrawIcon( this.ColumnIcon, bounds.X, bounds.Y );
    }
  }
}

您可以看到我定义了公共属性ColumnIcon,因此我可以指定我需要在此类之外显示的图标。

现在,要在DataGrid上实际使用它,你需要一个代码片段:

DataGridTableStyle ts = new DataGridTableStyle();

DataGridIconColumn dgic = new DataGridIconColumn();
dgic.ColumnIcon = Properties.Resources.MyIcon;
dgic.MappingName = "<your_column_name>";
dgic.HeaderText = "<your_column_header>";

ts.GridColumnStyles.Add(dgic);

this.myDataGrid.TableStyles.Add( ts );

这是应用DataGridTableStyle的一个非常简单的示例 - 我实际上对其余DataGrid列进行了大量进一步的自定义。但它应该让你开始你想做的事情。

答案 1 :(得分:1)

我知道如何做到这一点的唯一方法就是通过使用技巧在网格上绘制一些图像来渲染网格中的文本框。

其中一个CF team posted something about customising the grid on their site.

答案 2 :(得分:1)

答案 3 :(得分:0)

如果您能够使用第三方解决方案,请查看Resco SmartGrid

答案 4 :(得分:0)

http://www.cf-technologies.net/compactgrid.php。您可以使用单元格的CustomDraw事件..