GridColumnStylesCollection.IndexOf(DataGridColumnStyle) GridColumnStylesCollection.IndexOf(DataGridColumnStyle) GridColumnStylesCollection.IndexOf(DataGridColumnStyle) GridColumnStylesCollection.IndexOf(DataGridColumnStyle) Method

定义

获取指定 DataGridColumnStyle 的索引。Gets the index of a specified DataGridColumnStyle.

public:
 int IndexOf(System::Windows::Forms::DataGridColumnStyle ^ element);
public int IndexOf (System.Windows.Forms.DataGridColumnStyle element);
member this.IndexOf : System.Windows.Forms.DataGridColumnStyle -> int
Public Function IndexOf (element As DataGridColumnStyle) As Integer

参数

返回

DataGridColumnStyleGridColumnStylesCollection 的从零开始的索引;或者如果不存在相应的 DataGridColumnStyle,则为 -1。The zero-based index of the DataGridColumnStyle within the GridColumnStylesCollection or -1 if no corresponding DataGridColumnStyle exists.

示例

下面的代码示例使用Contains方法来确定中GridColumnStylesCollection是否存在给定DataGridColumnStyle的。The following code example uses the Contains method to determine if a given DataGridColumnStyle exists in a GridColumnStylesCollection. 如果是这样, IndexOf则该方法将返回的DataGridColumnStyle索引,并Remove通过索引调用方法,以从集合中移除元素。If so, the IndexOf method returns the index of the DataGridColumnStyle, and the Remove method is invoked with the index to remove the element from the collection.

Private Sub RemoveCol(ByVal dc As DataColumn) 
    Dim myGridColumns As GridColumnStylesCollection
    myGridColumns = DataGrid1.TableStyles(0).GridColumnStyles

    If myGridColumns.Contains("FirstName") Then
        Dim i As Integer
        i = myGridColumns.IndexOf(myGridColumns("FirstName"))
        myGridColumns.RemoveAt(i)
    End If
End Sub 

注解

使用方法确定是否存在特定DataGridColumnStyle的。 ContainsUse the Contains method to determine if a specific DataGridColumnStyle exists. 如果是,并且需要集合中元素的索引,请使用IndexOf方法。If so, and you need the index of the element within the collection, use the IndexOf method.

适用于

另请参阅