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();}
        }
相关推荐
上位机付工5 小时前
C#与倍福TwinCAT3进行ADS通信
开发语言·c#
土了个豆子的6 小时前
02.继承MonoBehaviour的单例模式基类
开发语言·visualstudio·单例模式·c#·里氏替换原则
疯狂的维修6 小时前
c#中public类比博图
c#·自动化
土了个豆子的9 小时前
03.缓存池
开发语言·前端·缓存·visualstudio·c#
xiaowu0801 天前
策略模式-不同的鸭子的案例
开发语言·c#·策略模式
VisionPowerful1 天前
九.弗洛伊德(Floyd)算法
算法·c#
ArabySide1 天前
【C#】 资源共享和实例管理:静态类,Lazy<T>单例模式,IOC容器Singleton我们该如何选
单例模式·c#·.net core
gc_22991 天前
C#测试调用OpenXml操作word文档的基本用法
c#·word·openxml
almighty271 天前
C#海康车牌识别实战指南带源码
c#·海康车牌识别·c#实现车牌识别·车牌识别源码·c#车牌识别
c#上位机2 天前
wpf之TextBlock
c#·wpf