DataGridColumnStyle Constructor (PropertyDescriptor)

 

Initializes a new instance of the DataGridColumnStyle class with the specified PropertyDescriptor.

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

public DataGridColumnStyle(
	PropertyDescriptor prop
)

Parameters

prop
Type: System.ComponentModel.PropertyDescriptor

A PropertyDescriptor that provides the attributes for the column.

To create a new DataGridColumnStyle, you must first get the CurrencyManager for the data source of the table to which the column will be added. See the CurrencyManager and BindingManager for details on getting specific CurrencyManager objects for a form.

From the CurrencyManager, you can then get the PropertyDescriptor for the DataColumn that will supply the data for the column.

When you create an instance of a DataGridColumnStyle, the following read/write properties are initialized.

Property

Initial value

Alignment

HorizontalAlignment.Left

DataGridTableStyle

null

FontHeight

-1

Invalidate

false

NullText

"(null)"

ReadOnly

false

The following code example creates a new DataGridTextBoxColumn (derived from DataGridColumnStyle) and adds it to the GridColumnStylesCollection of a DataGridTableStyle.

private void CreateNewDataGridColumnStyle(){
  DataSet myDataSet = new DataSet("myDataSet");
   // Insert code to populate the DataSet.

   // Get the CurrencyManager for the table you want to add a column to.
  CurrencyManager myCurrencyManager = 
  (CurrencyManager)this.BindingContext[myDataSet, "Suppliers"];

  // Get the PropertyDescriptor for the DataColumn.
  PropertyDescriptor pd = myCurrencyManager.GetItemProperties()["City"];

   // Construct the DataGridColumnStyle with the PropertyDescriptor.
  DataGridColumnStyle myColumn = new DataGridTextBoxColumn(pd);
  myColumn.MappingName = "City";
  dataGrid1.TableStyles[0].GridColumnStyles.Add(myColumn);
}

.NET Framework
Available since 1.1
Return to top
Show: