DataGridViewRowCollection.AddCopies(Int32, Int32) 方法

定義

根據指定索引的資料列,將指定的資料列數加入集合。

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

參數

indexSource
Int32

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

count
Int32

要加入 DataGridViewRowCollection 的資料列數目。

傳回

已加入的最後一個資料列索引。

例外狀況

indexSource 小於零,或大於等於控制項的資料列數目。

-或-

count 小於零。

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

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

  • 清除選取範圍。

-或-

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

-或-

DataGridViewDataSource 屬性不是 null

-或-

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

備註

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

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

適用於

另請參閱