代码之家  ›  专栏  ›  技术社区  ›  Wahid Bitar

无法允许用户使用List<>Datasource向DataGridView添加行

  •  12
  • Wahid Bitar  · 技术社区  · 16 年前

    DataGridView DataSource 着手 List<myClass>

    但是,当我设置时,新行指示器不显示 AllowUserToAddRows true ,

    当我设置 数据来源 BindingList<myClass> ,这似乎解决了问题。

    Q List<> 具有 BindingList<> 还是有更好的解决办法?

    1 回复  |  直到 6 年前
        1
  •  23
  •   Marc Gravell    16 年前

    myClass BindingList<T> 和覆盖 AddNewCore

    (编辑)或者-只需将列表包装成 BindingSource 它可能会起作用:

    using System;
    using System.Windows.Forms;
    using System.Collections.Generic;
    public class Person {
        public string Name { get; set; }
    
        [STAThread]
        static void Main() {
            var people = new List<Person> { new Person { Name = "Fred" } };
            BindingSource bs = new BindingSource();
            bs.DataSource = people;
    
            Application.Run(new Form { Controls = { new DataGridView {
                Dock = DockStyle.Fill, DataSource = bs } } });
        }
    }
    
    推荐文章