Export (0) Print
Expand All

DataGridViewImageColumn.Image Property

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.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public Image Image { get; set; }

Property Value

Type: System.Drawing.Image
The Image to display. The default is null.

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.

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.


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);
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft