網(wǎng)站首頁 編程語言 正文
datagridview手動(dòng)添加行數(shù)據(jù)
我在做軟件模型界面時(shí),通過功能按鈕觸發(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)生對應(yīng)數(shù)據(jù)的行數(shù)據(jù)了。如果不自動(dòng)產(chǎn)生列,則需手動(dòng)添加列,把列的數(shù)據(jù)源屬性名(DataPropertyName)設(shè)置為對應(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);
另外,訪問行單元格的方式可以這樣
this.dataGridView1.Rows[1].Cells[0].Value = "new value";
//或者,等價(jià)的
this.dataGridView1[0, 1].Value = "new value";
原文鏈接:https://blog.csdn.net/simpleshao/article/details/78642589
相關(guān)推薦
- 2022-08-21 Android使用貝塞爾曲線畫心形_Android
- 2022-04-20 Python設(shè)計(jì)模式創(chuàng)建型原型模式_python
- 2022-08-15 springboot使用配置文件配置bean屬性產(chǎn)生中文亂碼問題
- 2023-03-22 Python裝飾器使用方法全面梳理_python
- 2022-04-21 Flutter?設(shè)置全局字體的實(shí)現(xiàn)_Android
- 2022-12-11 C語言實(shí)現(xiàn)用?*?打印X形圖案_C 語言
- 2022-08-01 Python+pyecharts繪制雙動(dòng)態(tài)曲線教程詳解_python
- 2022-05-19 C++STL之string類的使用_C 語言
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支