DataGridViewImageColumn.Image 属性

定义

当没有设置单元格的 Value 属性,而且单元格的 ValueIsIcon 属性被设置为 false 时,获取或设置在此列的单元格中显示的图像。

public:
 property System::Drawing::Image ^ Image { System::Drawing::Image ^ get(); void set(System::Drawing::Image ^ value); };
public System.Drawing.Image Image { get; set; }
member this.Image : System.Drawing.Image with get, set
Public Property Image As Image

属性值

Image

要显示的 Image。 默认值为 null

示例

下面的代码示例演示如何设置默认图像。 此示例是 How to: Work with Image Columns in the Windows 窗体 DataGridView Control 中提供的大型示例的一部分。

void CreateColumns()
{
   DataGridViewImageColumn^ imageColumn;
   int columnCount = 0;
   do
   {
      Bitmap^ unMarked = blank;
      imageColumn = gcnew DataGridViewImageColumn;
      
      //Add twice the padding for the left and 
      //right sides of the cell.
      imageColumn->Width = x->Width + 2 * bitmapPadding + 1;
      imageColumn->Image = unMarked;
      dataGridView1->Columns->Add( imageColumn );
      columnCount = columnCount + 1;
   }
   while ( columnCount < 3 );
}
private void CreateColumns()
{
    DataGridViewImageColumn imageColumn;
    int columnCount = 0;
    do
    {
        Bitmap unMarked = blank;
        imageColumn = new DataGridViewImageColumn();

        //Add twice the padding for the left and 
        //right sides of the cell.
        imageColumn.Width = x.Width + 2 * bitmapPadding + 1;

        imageColumn.Image = unMarked;
        dataGridView1.Columns.Add(imageColumn);
        columnCount = columnCount + 1;
    }
    while (columnCount < 3);
}
Private Sub CreateColumns()

    Dim imageColumn As DataGridViewImageColumn
    Dim columnCount As Integer = 0
    Do
        Dim unMarked As Bitmap = blank
        imageColumn = New DataGridViewImageColumn()

        ' Add twice the padding for the left and 
        ' right sides of the cell.
        imageColumn.Width = x.Width + 2 * bitmapPadding + 1

        imageColumn.Image = unMarked
        imageColumn.ImageLayout = DataGridViewImageCellLayout.NotSet
        imageColumn.Description = "default image layout"
        dataGridView1.Columns.Add(imageColumn)
        columnCount = columnCount + 1
    Loop While columnCount < 3
End Sub

注解

Image属性指定一个图像,该图像在列未绑定数据且单元格的属性设置为false不带值的单元格ValueIsIcon中显示。 对于单元格没有关联图像的数据绑定列,将显示标准错误图形。

如果要显示属性 Icon 而不是属性 Image,请改为设置 Icon 该属性并将 ValuesAreIcons 该属性设置为 true。 这可确保正确绘制 alpha Icon 通道。 还可以设置 ValueIsIcon 单个单元格的属性,以指示单元格在没有单元格值时是否显示 ImageIcon 属性值。

适用于

另请参阅