ערוך

שתף באמצעות


DataGridViewImageColumn.Image Property

Definition

Gets or sets the image displayed in the cells of this column when the cell's Value property is not set and the cell's ValueIsIcon property is set to false.

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

Property Value

The Image to display. The default is null.

Examples

The following code example demonstrates how to set the default image. This example is part of a larger example available in How to: Work with Image Columns in the Windows Forms 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

Remarks

The Image property specifies an image that is displayed in cells with no values when the column is not data-bound and the cell's ValueIsIcon property is set to false. For a data-bound column whose cells do not have an associated image, a standard error graphic is displayed.

If you want to display an Icon instead of an Image, set the Icon property instead and set the ValuesAreIcons property to true. This ensures that the alpha channel of the Icon is painted correctly. You can also set the ValueIsIcon property of individual cells to indicate whether the cell displays the Image or the Icon property value when there is no cell value.

Applies to

See also