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, который предоставляет атрибуты столбца.
Примеры
В следующем примере кода создается новый DataGridTextBoxColumn (производный отDataGridColumnStyle) и добавляется в GridColumnStylesCollection объект .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
Комментарии
Чтобы создать новую DataGridColumnStyle, необходимо сначала получить CurrencyManager источник данных таблицы, в которую будет добавлен столбец. CurrencyManager
Дополнительные сведения о получении определенных CurrencyManager
объектов для формы см. в этой BindingManager
статье.
CurrencyManagerЗатем можно получить PropertyDescriptor данные DataColumn для столбца.
При создании экземпляра объекта DataGridColumnStyleинициализируются следующие свойства чтения и записи.
Свойство | Начальное значение |
---|---|
Alignment | HorizontalAlignment.Left |
DataGridTableStyle | null |
FontHeight | -1 |
Invalidate | false |
NullText | "(null)" |
ReadOnly | false |