本文整理汇总了C#中System.Windows.Forms.DataGridViewRowCollection.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridViewRowCollection.AddRange方法的具体用法?C# DataGridViewRowCollection.AddRange怎么用?C# DataGridViewRowCollection.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了DataGridViewRowCollection.AddRange方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRows
// Workaround for bug that prevents DataGridViewRowCollection.AddRange
// from working when the row for new records is selected.
private void AddRows(params DataGridViewRow[] rows)
{
InsertRows(dataGridView1.RowCount - 1, rows);
}
// Workaround for bug that prevents DataGridViewRowCollection.InsertRange
// from working when any rows before the insertion index are selected.
private void InsertRows(int index, params DataGridViewRow[] rows)
{
System.Collections.Generic.List<int> selectedIndexes =
new System.Collections.Generic.List<int>();
foreach (DataGridViewRow row in dataGridView1.SelectedRows)
{
if (row.Index >= index)
{
selectedIndexes.Add(row.Index);
row.Selected = false;
}
}
dataGridView1.Rows.InsertRange(index, rows);
foreach (int selectedIndex in selectedIndexes)
{
dataGridView1.Rows[selectedIndex].Selected = true;
}
}