欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

datagridview實現(xiàn)手動添加行數(shù)據(jù)

 更新時間:2022年04月19日 11:40:26   作者:simpleshao  
這篇文章主要介紹了datagridview實現(xiàn)手動添加行數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

datagridview手動添加行數(shù)據(jù)

我在做軟件模型界面時,通過功能按鈕觸發(fā)顯示的datagridview中,為了方便,需要一些數(shù)據(jù),僅寫死數(shù)據(jù)就可以了,因此,不需要連接數(shù)據(jù)表,直接添加行就可以了。

代碼如下:

? ? ? ? int index = this.dataGridView1.Rows.Add();
? ? ? ? this.dataGridView1.Rows[index].Cells[0].Value = "1";
? ? ? ? this.dataGridView1.Rows[index].Cells[1].Value = "11";
? ? ? ? this.dataGridView1.Rows[index].Cells[2].Value = "1111";
? ? ? ? this.dataGridView1.Rows[index].Cells[3].Value = "11111";
? ? ? ? this.dataGridView1.Rows[index].Cells[4].Value = "111111";
? ? ? ? this.dataGridView1.Rows[index].Cells[5].Value = "1111111";
? ? ? ? this.dataGridView1.Rows[index].Cells[6].Value = "*-*";

datagridview添加行的幾種方式

1、數(shù)據(jù)綁定

dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = customersDataSet;

這樣就會自動產(chǎn)生對應(yīng)數(shù)據(jù)的行數(shù)據(jù)了。如果不自動產(chǎn)生列,則需手動添加列,把列的數(shù)據(jù)源屬性名(DataPropertyName)設(shè)置為對應(yīng)數(shù)據(jù)類的屬性名。

2、手動添加

? ?songsDataGridView.ColumnCount = 5;
? ?....
? ?songsDataGridView.Columns[0].Name = "Release Date";
? ?....

string[] row0 = { "11/22/1968", "29", "Revolution 9",?
"Beatles", "The Beatles [White Album]" };
songsDataGridView.Rows.Add(row0);

另外,訪問行單元格的方式可以這樣

this.dataGridView1.Rows[1].Cells[0].Value = "new value";
//或者,等價的
this.dataGridView1[0, 1].Value = "new value";

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論