使用Compact Framework在数据网格中显示图像

3

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

有什么提示吗?

5个回答

9

像其他人评论的那样,你需要自己编写。幸运的是,这并不太困难。

在我的应用程序中,我需要一种方法来在特定列中绘制一个16x16的图标。我创建了一个新类,它继承自DataGridColumnStyle,这使得通过DataGridTableStyle对象将其应用于DataGrid变得容易。

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列进行了更多的定制。但是它应该能够让你开始做你想要的事情。


如果我需要在单元格中加载图像?我该怎么做? - user3383301

1

1

0

0

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


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接