C#DataGridView的简单使用

首先创建一个DataGridView控件,然后创建列(包括列名的定义),

由于我不是和数据库进行连接,只是为了输出好看一点。

删除所有数据:

while (this.dataGridView1.Rows.Count != 0)
            {
                this.dataGridView1.Rows.RemoveAt(0);
            }

添加一行数据:

index = this.dataGridView1.Rows.Add();//获取新的一行

                this.dataGridView1.Rows[index].Cells[0].Value = “第一列”;
                this.dataGridView1.Rows[index].Cells[1].Value = “输出形式为字符串”;
                this.dataGridView1.Rows[index].Cells[2].Value = "第三列";
           

原文地址:https://www.cnblogs.com/Anxc/p/10564964.html