DataGridColumnStyle Constructor (PropertyDescriptor^)
Initializes a new instance of the DataGridColumnStyle class with the specified PropertyDescriptor.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
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 |
|---|---|
HorizontalAlignment.Left | |
null | |
-1 | |
false | |
"(null)" | |
false |
The following code example creates a new DataGridTextBoxColumn (derived from DataGridColumnStyle) and adds it to the GridColumnStylesCollection of a DataGridTableStyle.
void CreateNewDataGridColumnStyle() { DataSet^ myDataSet = gcnew DataSet( "myDataSet" ); // Insert code to populate the DataSet. // Get the CurrencyManager for the table you want to add a column to. CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[myDataSet, "Suppliers"]); // Get the PropertyDescriptor for the DataColumn. PropertyDescriptor^ pd = myCurrencyManager->GetItemProperties()[ "City" ]; // Construct the DataGridColumnStyle with the PropertyDescriptor. DataGridColumnStyle^ myColumn = gcnew DataGridTextBoxColumn( pd ); myColumn->MappingName = "City"; dataGrid1->TableStyles[ 0 ]->GridColumnStyles->Add( myColumn ); }
Available since 1.1