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();}
        }
相关推荐
清风与日月21 小时前
c# 集成激光雷达(以思岚A1为例)
开发语言·c#
无极小卒1 天前
如何在三维空间中生成任意方向的矩形内部点位坐标
开发语言·算法·c#
the白勺1 天前
RabbitMQ-基础-总结
开发语言·c#
专注VB编程开发20年1 天前
C#VB.NET中实现可靠的文件监控(新建、删除、改名、内容修改等事件的准确捕获)
spring·c#·.net·文件监控
yi碗汤园1 天前
【一文了解】C#反射
开发语言·unity·c#
T.Ree.1 天前
汇编_读写内存
开发语言·汇编·c#
czhc11400756631 天前
C#1114 枚举
开发语言·c#
曹牧1 天前
C#中,GetValueOrDefault方法
c#
SunnyDays10111 天前
使用 C# 实现 Excel 与 DataTable 相互转换
c#·excel转datatable·datatable转excel
獨枭2 天前
C# 本地项目引用失效与恢复全攻略
开发语言·c#·visual studio