Share via


DataGridColumnStyle 建構函式

定義

初始化 DataGridColumnStyle 類別的新執行個體。

多載

DataGridColumnStyle()

在衍生類別中,初始化 DataGridColumnStyle 類別的新執行個體。

DataGridColumnStyle(PropertyDescriptor)

使用指定的 DataGridColumnStyle 初始化 PropertyDescriptor 類別的新執行個體。

DataGridColumnStyle()

在衍生類別中,初始化 DataGridColumnStyle 類別的新執行個體。

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

備註

當您建立 的 DataGridColumnStyle 實例時,會初始化下列屬性。

屬性 預設值
Alignment HorizontalAlignment.Left
DataGridTableStyle null
FontHeight -1
Invalidate false
NullText 字串 「 (null) 」
ReadOnly false

另請參閱

適用於

DataGridColumnStyle(PropertyDescriptor)

使用指定的 DataGridColumnStyle 初始化 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)

參數

prop
PropertyDescriptor

PropertyDescriptor,提供資料行屬性 (Attribute)。

範例

下列程式碼範例會建立衍生自 DataGridColumnStyle) 的新 DataGridTextBoxColumn (,並將其新增至 GridColumnStylesCollectionDataGridTableStyle

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

備註

若要建立新的 DataGridColumnStyle ,您必須先取得 CurrencyManager 要加入資料行之資料表資料來源的 。 如需取得表單特定 CurrencyManager 物件的詳細資訊, CurrencyManager 請參閱 和 BindingManager

CurrencyManager然後,您可以從 取得 PropertyDescriptor DataColumn 提供資料行資料的 。

當您建立 的 DataGridColumnStyle 實例時,會初始化下列讀取/寫入屬性。

屬性 初始值
Alignment HorizontalAlignment.Left
DataGridTableStyle null
FontHeight -1
Invalidate false
NullText 「 (null) 」
ReadOnly false

另請參閱

適用於