DataGridViewRowCollection.InsertCopies(Int32, Int32, Int32) 方法

定義

將資料列插入位在指定位置中的集合。

public:
 virtual void InsertCopies(int indexSource, int indexDestination, int count);
public virtual void InsertCopies (int indexSource, int indexDestination, int count);
abstract member InsertCopies : int * int * int -> unit
override this.InsertCopies : int * int * int -> unit
Public Overridable Sub InsertCopies (indexSource As Integer, indexDestination As Integer, count As Integer)

參數

indexSource
Int32

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

indexDestination
Int32

要插入資料列的位置。

count
Int32

要加入 DataGridViewRowCollectionDataGridViewRow 物件數目。

例外狀況

indexSource 小於零或大於集合中的資料列數目減一。

-或-

indexDestination 小於零或大於集合中的資料列數目。

-或-

count 小於 1。

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

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

  • 清除選取範圍。

-或-

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

-或-

indexDestination 等於集合中的資料列數目,且 AllowUserToAddRowstrue

-或-

這項作業會在未凍結的資料列之後插入凍結的資料列,或是在凍結的資料列之前插入未凍結的資料列。

備註

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

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

適用於

另請參閱