GridColumnStylesCollection.Contains 方法

定义

获取一个值,该值指示 GridColumnStylesCollection 是否包含特定的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains a specific DataGridColumnStyle.

重载

Contains(String)

获取一个值,该值指示 GridColumnStylesCollection 是否包含具有指定名称的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the DataGridColumnStyle with the specified name.

Contains(DataGridColumnStyle)

获取一个值,该值指示 GridColumnStylesCollection 是否包含指定的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the specified DataGridColumnStyle.

Contains(PropertyDescriptor)

获取一个值,该值指示 GridColumnStylesCollection 是否包含与指定 DataGridColumnStyle 关联的 PropertyDescriptorGets a value indicating whether the GridColumnStylesCollection contains a DataGridColumnStyle associated with the specified PropertyDescriptor.

Contains(String)

获取一个值,该值指示 GridColumnStylesCollection 是否包含具有指定名称的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the DataGridColumnStyle with the specified name.

public:
 bool Contains(System::String ^ name);
public bool Contains (string name);
member this.Contains : string -> bool
Public Function Contains (name As String) As Boolean

参数

name
String

所需 MappingNameDataGridColumnStyleThe MappingName of the desired DataGridColumnStyle.

返回

如果该集合包含 DataGridColumnStyle,则为 true;否则为 falsetrue if the collection contains the DataGridColumnStyle; otherwise, false.

示例

下面Contains的代码示例使用方法来确定DataGridColumnStyleGridColumnStylesCollection是否存在具有给定MappingName的。The following code example uses the Contains method to determine if a DataGridColumnStyle with a given MappingName exists in the GridColumnStylesCollection.

Private Sub ContainsThisDataCol()
    ' Use the Contains method to determine whether a specific
    ' DataGridColumnStyle with the same MappingName exists.
    Console.WriteLine(DataGrid1.TableStyles(0). _
    GridColumnStyles.Contains("FirstName"))
End Sub    

注解

的标题是HeaderText使用DataGridColumnStyle属性设置的。The caption of a DataGridColumnStyle is set with the HeaderText property.

在调用Contains DataGridColumnStyle 方法删除项之前,使用方法确定是否Remove存在特定的。Use the Contains method to determine if a particular DataGridColumnStyle exists before invoking the Remove method to remove the item. 如果需要了解特定DataGridColumnStyle的索引,请IndexOf使用方法。If you need to know the index of a particular DataGridColumnStyle, use the IndexOf method.

另请参阅

Contains(DataGridColumnStyle)

获取一个值,该值指示 GridColumnStylesCollection 是否包含指定的 DataGridColumnStyleGets a value indicating whether the GridColumnStylesCollection contains the specified DataGridColumnStyle.

public:
 bool Contains(System::Windows::Forms::DataGridColumnStyle ^ column);
public bool Contains (System.Windows.Forms.DataGridColumnStyle column);
member this.Contains : System.Windows.Forms.DataGridColumnStyle -> bool
Public Function Contains (column As DataGridColumnStyle) As Boolean

参数

返回

如果该集合包含 DataGridColumnStyle,则为 true;否则为 falsetrue if the collection contains the DataGridColumnStyle; otherwise, false.

示例

下面的代码示例使用Contains方法来确定GridColumnStylesCollection是否包含特定DataGridColumnStyle的。The following code example uses the Contains method to determine if a GridColumnStylesCollection contains a specific DataGridColumnStyle.

Private Sub ContainsThisDataCol()
   Dim myGridColumnCol As GridColumnStylesCollection
   myGridColumnCol = dataGrid1.TableStyles(0).GridColumnStyles
   ' Get the CurrencyManager for the table you want to add a column to.
   Dim myCurrencyManager As CurrencyManager = _
   CType(Me.BindingContext(ds.Tables("Suppliers")), CurrencyManager)
   ' Get the PropertyDescriptor for the DataColumn of the new column.
   Dim pd As PropertyDescriptor = _
   myCurrencyManager.GetItemProperties()("City")
   Dim myColumn As New DataGridTextBoxColumn()
   myColumn.PropertyDescriptor = pd
   ' Test to see if the present columns contains the new object.
   Console.WriteLine(DataGrid1.TableStyles(0).GridColumnStyles. _
   Contains(myColumn))
End Sub

注解

在调用Contains DataGridColumnStyle 方法删除项之前,使用方法确定是否Remove存在特定的。Use the Contains method to determine if a particular DataGridColumnStyle exists before invoking the Remove method to remove the item. 如果需要了解特定DataGridColumnStyle的索引,请IndexOf使用方法。If you need to know the index of a particular DataGridColumnStyle, use the IndexOf method.

另请参阅

Contains(PropertyDescriptor)

获取一个值,该值指示 GridColumnStylesCollection 是否包含与指定 DataGridColumnStyle 关联的 PropertyDescriptorGets a value indicating whether the GridColumnStylesCollection contains a DataGridColumnStyle associated with the specified PropertyDescriptor.

public:
 bool Contains(System::ComponentModel::PropertyDescriptor ^ propDesc);
public bool Contains (System.ComponentModel.PropertyDescriptor propDesc);
member this.Contains : System.ComponentModel.PropertyDescriptor -> bool
Public Function Contains (propDesc As PropertyDescriptor) As Boolean

参数

propertyDescriptor
PropertyDescriptor

与所需 PropertyDescriptor 关联的 DataGridColumnStyleThe PropertyDescriptor associated with the desired DataGridColumnStyle.

返回

如果该集合包含 DataGridColumnStyle,则为 true;否则为 falsetrue if the collection contains the DataGridColumnStyle; otherwise, false.

示例

下面Contains的代码示例使用方法来确定GridColumnStylesCollection是否包含与指定PropertyDescriptor关联DataGridColumnStyle的。The following code example uses the Contains method to determine if a GridColumnStylesCollection contains a DataGridColumnStyle associated with a specified PropertyDescriptor.

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

   Dim trueOrFalse As Boolean
   ' Set the variable to a known column in the grid's DataTable.
   trueOrFalse = DataGrid1.TableStyles(0).GridColumnStyles. _
   Contains(myPropertyDescriptor)
   Console.WriteLine(trueOrFalse)
End Sub 

注解

若要获取PropertyDescriptorCollection,请GetItemProperties使用BindingManagerBase类的方法。To get a PropertyDescriptorCollection, use the GetItemProperties method of the BindingManagerBase class. MappingName PropertyDescriptor将的传递Item[String] 到的PropertyDescriptorCollection属性,以返回特定列的。 DataGridColumnStylePass the MappingName of the DataGridColumnStyle to the Item[String] property of the PropertyDescriptorCollection to return the PropertyDescriptor for a specific column.

在调用Contains DataGridColumnStyle 方法删除项之前,使用方法确定是否Remove存在特定的。Use the Contains method to determine if a particular DataGridColumnStyle exists before invoking the Remove method to remove the item. 如果需要了解特定DataGridColumnStyle的索引,请IndexOf使用方法。If you need to know the index of a particular DataGridColumnStyle, use the IndexOf method.

另请参阅

适用于