datagridview实现手动添加行数据
作者:simpleshao 时间:2022-03-29 16:31:09
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
标签:datagridview,添加,行数据
0
投稿
猜你喜欢
详解Java编程中protected修饰符与static修饰符的作用
2022-05-11 03:53:17
shiro之记住登录信息
2023-03-06 18:39:13
Java数据结构学习之栈和队列
2022-02-21 11:32:45
Android实现屏幕旋转方法总结
2023-04-01 19:37:31
Spring Boot Logback配置日志过程解析
2022-12-09 18:08:06
C# 多线程编程技术基础知识入门
2023-05-27 08:00:24
C#用Activex实现Web客户端读取RFID功能的代码
2021-10-28 21:07:36
C#中OpenCvSharp 通过特征点匹配图片的方法
2023-07-14 08:10:55
SpringBoot微信消息接口配置详解
2023-08-23 09:51:21
java9开始——接口中可以定义private私有方法
2023-03-27 06:53:15
Android游戏开发学习之引擎用法实例详解
2023-09-26 16:01:57
Java lombok中@Accessors注解三个属性的作用
2022-04-20 14:32:27
C#实现简单的JSON序列化功能代码实例
2023-06-21 09:03:52
详解Maven多模块打包遇到的问题解决方法
2022-12-25 13:01:12
Android5.0新控件实例详解
2022-12-06 21:58:18
Java实现简单的五子棋小游戏
2023-11-25 07:36:13
详解StackExchange.Redis通用封装类分享
2022-07-06 00:41:32
Android一行代码实现圆形头像
2022-02-23 02:00:25
详细理解JAVA面向对象的封装,继承,多态,抽象
2023-07-05 06:54:14
在Java中int和byte[]的相互转换
2023-09-23 15:35:45