Export (0) Print
Expand All

DataGridViewCellStyle.Padding Property

Gets or sets the space between the edge of a DataGridViewCell and its content.

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

public Padding Padding { get; set; }

Property Value

Type: System.Windows.Forms.Padding
A Padding that represents the space between the edge of a DataGridViewCell and its content.

Setting the Padding property affects where the editing control of the DataGridViewCell is drawn. For example, if you set Padding on a DataGridViewTextBoxCell to a System.Windows.Forms.Padding that has a value of 10 for its Left, Top, Right, and Bottom properties, the content of the cell is drawn in the middle of the cell with a space of 10 pixels between the edges of the text box and the edges of the cell.

The following code example illustrates the use of this property in a DataGridView control that contains owner-drawn rows. Each row displays text that spans the entire width of the row underneath the regular cell content. The Padding property is used to provide the extra space for this text. In the example, the extra height required is stored in a constant called CUSTOM_CONTENT_HEIGHT.

This code example is part of a larger example. For the complete example, see How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.


// Set a cell padding to provide space for the top of the focus 
// rectangle and for the content that spans multiple columns. 
Padding newPadding = new Padding(0, 1, 0, CUSTOM_CONTENT_HEIGHT);
this.dataGridView1.RowTemplate.DefaultCellStyle.Padding = newPadding;

// Set the selection background color to transparent so 
// the cell won't paint over the custom selection background.
this.dataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor =
    Color.Transparent;

// Set the row height to accommodate the content that 
// spans multiple columns.
this.dataGridView1.RowTemplate.Height += CUSTOM_CONTENT_HEIGHT;


.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