網站首頁 編程語言 正文
datagridview手動添加行數據
我在做軟件模型界面時,通過功能按鈕觸發顯示的datagridview中,為了方便,需要一些數據,僅寫死數據就可以了,因此,不需要連接數據表,直接添加行就可以了。
代碼如下:
? ? ? ? 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、數據綁定
dataGridView1.AutoGenerateColumns = true;
dataGridView1.DataSource = customersDataSet;
這樣就會自動產生對應數據的行數據了。如果不自動產生列,則需手動添加列,把列的數據源屬性名(DataPropertyName)設置為對應數據類的屬性名。
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";
原文鏈接:https://blog.csdn.net/simpleshao/article/details/78642589
相關推薦
- 2022-04-11 Maven如果將本地jar包添加到pom中
- 2023-03-16 淺析Kotlin使用infix函數構建可讀語法流程講解_Android
- 2022-09-16 Pandas數值排序?sort_values()的使用_python
- 2022-09-23 Golang分布式應用定時任務示例詳解_Golang
- 2022-10-13 Python中?whl包、tar.gz包的區別詳解_python
- 2022-06-06 Array.prototype.myjoin
- 2022-03-17 Qt編寫提示進度條的實現示例_C 語言
- 2022-08-01 Qt實現簡易毛玻璃效果的示例代碼_C 語言
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支