Gets or sets the space between the edge of a DataGridViewCell and its content.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Setting the property affects where the editing control of the DataGridViewCell is drawn. For example, if you set 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 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;
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)