DataGridViewRowCollection.AddCopy(Int32) 方法

定義

以指定索引處的資料列為基底加入新的資料列。

public:
 virtual int AddCopy(int indexSource);
public virtual int AddCopy (int indexSource);
abstract member AddCopy : int -> int
override this.AddCopy : int -> int
Public Overridable Function AddCopy (indexSource As Integer) As Integer

參數

indexSource
Int32

當成新資料列基底的資料列索引。

傳回

新資料列的索引。

例外狀況

indexSource 小於零,或大於等於集合的資料列數目。

關聯的 DataGridView 控制項正在執行下列其中一個動作,會暫時防止加入新的資料列:

  • 選取控件中的所有儲存格。

  • 清除選取範圍。

-或-

針對下列其中一個 DataGridView 事件 ,從處理常式呼叫這個方法:

-或-

DataGridViewDataSource 屬性不是 null

-或-

這項作業會將凍結的資料列加在未凍結的資料列後面。

備註

InheritedStyle新數據列的 屬性與位於 indexSource的數據列具有相同的值InheritedStyle。 如果可能的話,此方法 AddCopy 會將共享資料列加入至 DataGridViewRowCollection。 否則,新數據列會取消共用。 如需詳細資訊,請參閱 縮放 Windows Form DataGridView 控制項的最佳做法

加入新數據列時,控件中的數據列不會自動排序。 若要將新數據列排序成正確的位置,請在事件處理程式中DataGridView.RowsAdded呼叫 DataGridView.Sort 方法。 您也可以在事件處理程式中CellValueChanged呼叫 DataGridView.Sort 方法,以在使用者修改儲存格時排序數據列。

適用於

另請參閱