Bewerken

Delen via


GridColumnStylesCollection.Item[] Property

Definition

Overloads

Item[Int32]

Gets the DataGridColumnStyle at a specified index.

Item[String]

Gets the DataGridColumnStyle with the specified name.

Item[PropertyDescriptor]

Gets the DataGridColumnStyle associated with the specified PropertyDescriptor.

Item[Int32]

Gets the DataGridColumnStyle at a specified index.

public:
 property System::Windows::Forms::DataGridColumnStyle ^ default[int] { System::Windows::Forms::DataGridColumnStyle ^ get(int index); };
public System.Windows.Forms.DataGridColumnStyle this[int index] { get; }
member this.Item(int) : System.Windows.Forms.DataGridColumnStyle
Default Public ReadOnly Property Item(index As Integer) As DataGridColumnStyle

Parameters

index
Int32

The zero-based index of the DataGridColumnStyle to return.

Property Value

The specified DataGridColumnStyle.

Examples

The following code example gets the DataGridColumnStyle using the Item[] property.

Private Sub GetGridColumn()
    Dim myDataGridColumnStyle As DataGridColumnStyle 
    ' Get the DataGridColumnStyle at the specified index.
    myDataGridColumnStyle = _
    DataGrid1.TableStyles(0).GridColumnStyles(0)
    Console.WriteLine(myDataGridColumnStyle.MappingName)
End Sub

Remarks

Use the IndexOf method to determine the index of any element in the collection.

Applies to

Item[String]

Gets the DataGridColumnStyle with the specified name.

public:
 property System::Windows::Forms::DataGridColumnStyle ^ default[System::String ^] { System::Windows::Forms::DataGridColumnStyle ^ get(System::String ^ columnName); };
public System.Windows.Forms.DataGridColumnStyle this[string columnName] { get; }
member this.Item(string) : System.Windows.Forms.DataGridColumnStyle
Default Public ReadOnly Property Item(columnName As String) As DataGridColumnStyle

Parameters

columnName
String

The MappingName of the DataGridColumnStyle to retrieve.

Property Value

The DataGridColumnStyle with the specified column header.

Examples

The following code example returns the DataGridColumnStyle named in the Item[] property.

Private Sub GetGridColumn()
    Dim myDataGridColumnStyle As DataGridColumnStyle 
    ' Get the DataGridColumnStyle at the specified index.
    myDataGridColumnStyle = _
    DataGrid1.TableStyles(0).GridColumnStyles("Fname")
    Console.WriteLine(myDataGridColumnStyle.MappingName)
End Sub

Remarks

The column header of a DataGridColumnStyle can be set explicitly by setting the HeaderText property. By default, the HeaderText is set using uses MappingName property value.

The comparison between column headers and the value to look for is not case-sensitive.

Applies to

Item[PropertyDescriptor]

Gets the DataGridColumnStyle associated with the specified PropertyDescriptor.

public:
 property System::Windows::Forms::DataGridColumnStyle ^ default[System::ComponentModel::PropertyDescriptor ^] { System::Windows::Forms::DataGridColumnStyle ^ get(System::ComponentModel::PropertyDescriptor ^ propDesc); };
public:
 property System::Windows::Forms::DataGridColumnStyle ^ default[System::ComponentModel::PropertyDescriptor ^] { System::Windows::Forms::DataGridColumnStyle ^ get(System::ComponentModel::PropertyDescriptor ^ propertyDesciptor); };
public System.Windows.Forms.DataGridColumnStyle this[System.ComponentModel.PropertyDescriptor propDesc] { get; }
public System.Windows.Forms.DataGridColumnStyle this[System.ComponentModel.PropertyDescriptor propertyDesciptor] { get; }
member this.Item(System.ComponentModel.PropertyDescriptor) : System.Windows.Forms.DataGridColumnStyle
Default Public ReadOnly Property Item(propDesc As PropertyDescriptor) As DataGridColumnStyle
Default Public ReadOnly Property Item(propertyDesciptor As PropertyDescriptor) As DataGridColumnStyle

Parameters

propDescpropertyDesciptor
PropertyDescriptor

The PropertyDescriptor associated with the DataGridColumnStyle.

Property Value

The DataGridColumnStyle associated the specified PropertyDescriptor.

Examples

The following code example gets a DataColumn from a DataTable in a DataSet, and then passes it as an argument to the Add method.

Private Sub ContainsThisDataCol()
    Dim myPropertyDescriptor As PropertyDescriptor
    Dim myPropertyDescriptorCollection As PropertyDescriptorCOllection
    myPropertyDescriptorCollection = _
    me.BindingContext(DataSet1, "Customers").GetItemProperties()
    myPropertyDescriptor = myPropertyDescriptorCollection("FirstName")

    Dim myDataGridColumnStyle As DataGridColumnStyle
    myDataGridColumnStyle = DataGrid1.TableStyles(0). _
    GridColumnStyles(myPropertyDescriptor)
End Sub

Remarks

Each DataGridColumnStyle is created using a PropertyDescriptor. The PropertyDescriptor can be returned using the PropertyDescriptor property.

To get the PropertyDescriptorCollection for a specific data source, use the GetItemProperties method of the BindingManagerBase class. Pass the MappingName to the Item[] property of the PropertyDescriptorCollection to return a PropertyDescriptor for a specific column.

See also

Applies to