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();}
        }
相关推荐
暖馒3 小时前
Modbus应用层协议的深度剖析
网络·网络协议·c#·wpf·智能硬件
刘欣的博客6 小时前
C# CS架构程序发版升级的走数据库方案
c#·单文件升级自己的方式
Yorlen_Zhang8 小时前
Python Tkinter Text 控件完全指南:从基础编辑器到富文本应用
开发语言·python·c#
不绝1918 小时前
C#进阶:预处理指令/反射,Gettype,Typeof/关键类
开发语言·c#
大鹏说大话8 小时前
告别 MSBuild 脚本混乱:用 C# 和 Nuke 构建清晰、可维护的现代化构建系统
开发语言·c#
czhc11400756639 小时前
通信 28
c#
bugcome_com13 小时前
C# 程序结构详解:从 Hello World 开始
c#
唐梓航-求职中14 小时前
编程-技术-算法-leetcode-288. 单词的唯一缩写
算法·leetcode·c#
bugcome_com16 小时前
阿里云 OSS C# SDK 使用实践与参数详解
阿里云·c#
懒人咖1 天前
缺料分析时携带用料清单的二开字段
c#·金蝶云星空