Editar

Compartilhar via


DataGridColumnStyle Constructors

Definition

Initializes a new instance of the DataGridColumnStyle class.

Overloads

DataGridColumnStyle()

In a derived class, initializes a new instance of the DataGridColumnStyle class.

DataGridColumnStyle(PropertyDescriptor)

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

DataGridColumnStyle()

In a derived class, initializes a new instance of the DataGridColumnStyle class.

public:
 DataGridColumnStyle();
public DataGridColumnStyle ();
Public Sub New ()

Remarks

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

Property Default value
Alignment HorizontalAlignment.Left
DataGridTableStyle null
FontHeight -1
Invalidate false
NullText The string "(null)"
ReadOnly false

See also

Applies to

DataGridColumnStyle(PropertyDescriptor)

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

public:
 DataGridColumnStyle(System::ComponentModel::PropertyDescriptor ^ prop);
public DataGridColumnStyle (System.ComponentModel.PropertyDescriptor prop);
new System.Windows.Forms.DataGridColumnStyle : System.ComponentModel.PropertyDescriptor -> System.Windows.Forms.DataGridColumnStyle
Public Sub New (prop As PropertyDescriptor)

Parameters

prop
PropertyDescriptor

A PropertyDescriptor that provides the attributes for the column.

Examples

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 );
}
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);
}
Private Sub CreateNewDataGridColumnStyle()
   Dim myDataSet As New DataSet("myDataSet")
   ' Insert code to populate the DataSet.

   ' Get the CurrencyManager for the table you want to add a column to.
   Dim myCurrencyManager As CurrencyManager = CType _
   (Me.BindingContext(myDataSet.Tables("Suppliers")), CurrencyManager)

   ' Get the PropertyDescriptor for the DataColumn.
   Dim pd As PropertyDescriptor = _
   myCurrencyManager.GetItemProperties()("City")

   ' Construct the DataGridColumnStyle with the PropertyDescriptor.
   Dim myColumn As New DataGridTextBoxColumn(pd)
   myColumn.MappingName = "City"
   dataGrid1.TableStyles(0).GridColumnStyles.Add(myColumn)

End Sub

Remarks

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

See also

Applies to