扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

c#中datagridview怎么删除指定行

扬州沐宇科技
2024-03-27 18:31:49
c#

在C#中,可以通过以下代码删除指定行:

// 假设要删除第3行
int rowIndex = 2; // 行索引从0开始

if (dataGridView1.Rows.Count > rowIndex)
{
    dataGridView1.Rows.RemoveAt(rowIndex);
}

上面的代码中,首先指定要删除的行的索引,然后判断该索引是否在DataGridView的行数范围内,如果是则调用Rows.RemoveAt()方法删除指定行。

扫码添加客服微信