C# 在dataGridView中行首或行尾手動添加記錄、修改一行記錄(1.行尾添加,非數據庫連接形式 2.修改某一行的數據 3.插入行首,不覆蓋行首)

1. 在行尾添加新的一行數據
DataGridViewRow row = new DataGridViewRow();
row.CreateCells(dataGridView1);
row.Cells[0].Value = 23;
row.Cells[1].Value = 45;
this.dataGridView1.Rows.Add(row);


2. 修改某一行的數據

            int iRowIndex = n;
            this.dataGridView1["Column1", iRowIndex].Value = "1";
            this.dataGridView1["Column2", iRowIndex].Value = "張三";
            this.dataGridView1["Column3", iRowIndex].Value = "軟件部";


3. 在行首插入一天記錄,不會覆蓋原來數據,也可在任意位置插入

                DataGridViewRow row = new DataGridViewRow();
                row.CreateCells(dataGridView1);
                row.Cells[0].Value = "hh";
                row.Cells[1].Value = "yy";
                this.dataGridView1.Rows.Insert(0, row);


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章