DataColumnCollection.RemoveAt(Int32) 方法

定義

從集合移除在指定索引處的資料行。Removes the column at the specified index from the collection.

public:
 void RemoveAt(int index);
public void RemoveAt (int index);
member this.RemoveAt : int -> unit
Public Sub RemoveAt (index As Integer)

參數

index
Int32

要移除的資料行索引。The index of the column to remove.

例外狀況

集合的指定索引處不具有資料行。The collection does not have a column at the specified index.

範例

下列範例會先使用Contains方法來判斷是否在集合中找到特定資料行。The following example first uses the Contains method to determine whether a particular column is found in the collection. 如果找到, CanRemove方法會測試是否可以移除資料行。If it is found, the CanRemove method tests whether the column can be removed. 若是如此,則會使用RemoveAt方法移除該資料行。If so, the column is removed with the RemoveAt method.

Private Sub RemoveColumnAtIndex(thisIndex As Integer)
   ' Get the DataColumnCollection from a DataTable in a DataSet.
   Dim columns As DataColumnCollection = _
       DataSet1.Tables("Orders").Columns

   If columns.CanRemove(columns(thisIndex)) Then 
      columns.RemoveAt(thisIndex)
   End If
End Sub

備註

如果藉由加入或移除資料行成功變更集合,則CollectionChanged會發生此事件。If the collection is successfully changed by adding or removing columns, the CollectionChanged event occurs.

適用於

另請參閱