【问题标题】:which winforms control/approach to bind to a List<> collection of custom objects?哪个 winforms 控件/方法绑定到自定义对象的 List<> 集合?
【发布时间】:2010-12-03 19:34:01
【问题描述】:

我可以使用哪种控制方法来快速提供我的列表集合的可视化编辑。
我拥有的内存集合如下。

我的要求基本上是:

  1. 在我的 winform 表单上提供一种方法,允许添加/查看/编辑 ConfigFileDTO 信息列表,但是
  2. 只有 ConfigFileDTO 的“PATH”字段需要对用户可用,因此用户可以:
    • 在列表中添加一个新的 PATH,
    • 删除 PATH,从而从列表中删除 ConfigFileDTO,
    • 并编辑列表,允许更改列表中的 PATH 之一。

我的代码

    private static List<ConfigFileDTO> files;

    public class ConfigFileDTO
    {
        private string filename, content_type, path;
        private int file_size;
        private DateTime updated_at;

        public ConfigFileDTO() {  }

        public int FileSize {
            get { return this.file_size;  }
            set { this.file_size = value; }
        }    
        public string ContentType {
            get { return this.content_type; }
            set { this.content_type = value; }
        }    
        public string Filename {
            get { return this.filename; }
            set { this.filename = value; }
        }    
        public DateTime UpdatedAt {
            get { return this.updated_at; }
            set { this.updated_at = value; }
        }    
        public string Path {
            get { return this.path; }
            set { this.path = value; }
        }    
    }

谢谢

【问题讨论】:

    标签: c# winforms data-binding list


    【解决方案1】:

    如果您只想操作Path 列,那么通常最好手动设置列绑定(例如DataGridView);但是,您也可以使用[Browsable(false)](从显示中删除属性)和[ReadOnly(true)](将属性视为只读,即使它具有设置器)来控制属性(/列)的处理方式。

    如果您想控制如何创建新实例,请从 BindingList&lt;T&gt; 继承并覆盖 AddNewCore()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-01
      • 1970-01-01
      • 2020-05-17
      • 2013-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多