最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

我在做軟件模型界面時(shí),通過(guò)功能按鈕觸發(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;

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

2、手動(dòng)添加

? ?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);

另外,訪問(wèn)行單元格的方式可以這樣

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

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

相關(guān)文章

最新評(píng)論

来安县| 鹤山市| 罗江县| 阳泉市| 乌苏市| 中阳县| 理塘县| 郑州市| 兖州市| 泸溪县| 毕节市| 田东县| 石棉县| 绥德县| 公主岭市| 墨江| 海丰县| 古田县| 江北区| 交口县| 洛阳市| 子洲县| 容城县| 长岭县| 建阳市| 玛曲县| 朝阳区| 丰县| 漠河县| 敦化市| 敖汉旗| 界首市| 鹰潭市| 台山市| 安溪县| 太和县| 八宿县| 丹寨县| 元谋县| 江陵县| 化州市|