dataGridView 绑定List 显示内容不刷新

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

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

微软的Bug

参考代码

cs 复制代码
        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();}
        }
相关推荐
加号311 小时前
【C#】 文件与目录管理:创建、删除操作的技术解析
开发语言·c#
用户3952409988015 小时前
SqlSugar 连接 PostgreSQL 报错 42P01: relation does not exist 的排查与修复
c#
2601_9618752416 小时前
法考考试时间安排及科目|时间表|资料已整理
开发语言·c#·inverted-index·suffix-tree·sstable·r-tree·lsm-tree
ServBay16 小时前
你跟高级 C# 工程师的区别,就是这8个开发技巧
后端·c#·.net
2601_9618752421 小时前
法考备考计划表|学习计划|资料已整理
java·开发语言·学习·eclipse·tomcat·c#·hibernate
Y学院21 小时前
C#游戏脚本开发全流程(Unity通用完整版)
游戏·unity·c#
淡海水1 天前
38-Hybrid生态-LeanCLR总览
unity·架构·c#·热更新·clr·hybrid·leanclr
iCxhust1 天前
C# 生成命令行程序 将hex格式烧录程序转换成bin烧录格式
开发语言·汇编·单片机·嵌入式硬件·c#·微机原理
xiaoshuaishuai81 天前
C# 封装与继承
开发语言·c#
FL16238631291 天前
基于C#winform使用纯opencv部署ppocrv5和ppocrv6的onnx模型进行OCR文件检测识别
opencv·c#·ocr