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();}
        }
相关推荐
江沉晚呤时6 小时前
在 C# 中调用 Python 脚本:实现跨语言功能集成
python·microsoft·c#·.net·.netcore·.net core
Oberon7 小时前
Avalonia硬配.NET Framework 4.8
c#·.net·avalonia·.net framework
喵叔哟9 小时前
3. 【Blazor全栈开发实战指南】--Blazor是什么?为什么选择Blazor?
c#·.netcore
钢铁男儿12 小时前
C# 接口(接口可以继承接口)
java·算法·c#
小码编匠19 小时前
C# 的西门子数控系统 OPCUA 数据采集开发从零入门
后端·数据分析·c#
孜然卷k19 小时前
C#项目 在Vue/React前端项目中 使用使用wkeWebBrowser引用并且内部使用iframe网页外链 页面部分白屏
前端·vue.js·react.js·c#
专注VB编程开发20年20 小时前
C# VB.NET多进程-管道通信,命名管道(Named Pipes)
开发语言·c#·.net
唐青枫1 天前
C#.NET 泛型详解
c#·.net
阿蒙Amon1 天前
C#日期、时间和时区:全球化应用的时间处理艺术
java·服务器·c#
学不动CV了1 天前
深入理解C语言内存空间、函数指针(三)(重点是函数指针)
c语言·arm开发·数据库·stm32·单片机·嵌入式硬件·c#