当前位置: 首页 > news >正文

dataGridView 绑定List 显示内容不刷新

绑定后,原list值变动,显示内容会刷新

绑定后,list新添加的值时不会显示到界面,需要重新绑定list

微软的Bug

参考代码

        public class Student{public string Name { get; set; }}List<Student> list = new List<Student>();private void Form2_Load(object sender, EventArgs e){list.Add(new Student() { Name = "张三" });list.Add(new Student() { Name = "李四" });this.dataGridView1.DataSource= new BindingList<Student>(list);}private void button1_Click(object sender, EventArgs e){//注意  新添加的数据是无法展示到dgv里面的!!!list.Add(new Student() { Name = "王五" });list.Add(new Student() { Name = "赵六" });dataGridView1.Refresh();}private void button2_Click(object sender, EventArgs e){//元素删除list.RemoveAt(0);dataGridView1.Refresh();}private void button3_Click(object sender, EventArgs e){//元素修改list[0].Name=DateTime.Now.ToString();dataGridView1.Refresh();}private void button4_Click(object sender, EventArgs e){//重新绑定if (list.Count!=dataGridView1.Rows.Count){this.dataGridView1.DataSource=null;this.dataGridView1.DataSource= new BindingList<Student>(list);}
else{dataGridView1.Refresh();}}

http://www.lryc.cn/news/322288.html

相关文章:

  • VR历史建筑漫游介绍|虚拟现实体验店|VR设备购买
  • Linux查看硬件型号详细信息
  • 【鸿蒙HarmonyOS开发笔记】通知模块之发布基础类型通知,内含如何将图片变成PixelMap对象
  • 外包干了1个月,技术明显进步。。。
  • 鸿蒙开发实战:【Faultloggerd部件】
  • 蓝桥杯刷题|03普及-真题
  • 【动态三维重建】Deformable 3D Gaussians 可变形3D GS用于单目动态场景重建(CVPR 2024)
  • 智能驾驶域控制器行业介绍
  • [数据集][目标检测]焊接件表面缺陷检测数据集VOC+YOLO格式2292张10类别
  • 微信小程序的页面制作---常用组件及其属性
  • 什么样的网站不适合使用WordPress?
  • vulhub中GitLab 任意文件读取漏洞复现(CVE-2016-9086)
  • 【爬虫】web自动化和接口自动化
  • 哔哩哔哩后端Java一面
  • Vue.js前端开发零基础教学(二)
  • Bert模型输出:last_hidden_state转换为pooler_output
  • Docker Compose 基本语法
  • 【算法集训】基础算法:贪心
  • Centos7部署单节点MongoDB(V4.2.25)
  • 隐私计算笔记(1)
  • 查询方法需要使用事务吗?
  • 剑指offer面试题40 数组中只出现一次的数字
  • gitLab server version 13.12.1 is not supported
  • 如何在 iPhone 上使用蓝牙鼠标
  • matlab simulink 电力系统同步发电机励磁系统的建模与仿真
  • AI新工具(20240320) AI创作一首属于自己的音乐; 轻松制作具有透明背景的高质量图像
  • IT服务ITIL4 认证:助力企业数字化转型的必杀技!
  • 微软聘请了谷歌DeepMind的联合创始人
  • JavaMySQL高级一(下)
  • HCIA复习