在数据网格单元格中显示图像是否可能?我目前使用的是3.5紧凑框架。
有什么提示吗?
在数据网格单元格中显示图像是否可能?我目前使用的是3.5紧凑框架。
有什么提示吗?
像其他人评论的那样,你需要自己编写。幸运的是,这并不太困难。
在我的应用程序中,我需要一种方法来在特定列中绘制一个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
,这样我就可以在类外指定需要显示的图标。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
列进行了更多的定制。但是它应该能够让你开始做你想要的事情。