views:

61

answers:

1

Hi,

I'm new to winforms (using C#) and would appreciated a headsup re the winforms control/approach to use to quickly provide visual editing of my List collection. So the in-memory collection I have is below. So my requirements were basically to:

  1. provide a means on my winform form, to allow add/view/edit of the List of ConfigFileDTO information, BUT
  2. Only the "PATH" field of the ConfigFileDTO needs to be made a available to the user, therefore the use could: i) add a new PATH to the list, ii) delete PATHs, hence deleting the ConfigFileDTO from the list, and iii) edit the list, allowing one of the PATH's in the list to be changed.

    private static List<ConfigFileDTO> files;
    
    
    public class ConfigFileDTO
    {
        private string filename;
        private string content_type;
        private int file_size;
        private DateTime updated_at;
        private string path;
    
    
    
    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; }
    }
    
    }

Thanks

+1  A: 

If you only want the Path column to be manipulated, then it is usually better to simply set up the column bindings (for things like DataGridView) manually; however, you can also use things like [Browsable(false)] (removes a property from display) and [ReadOnly(true)] (treat a property as read-only even if it has a setter) to control how properties (/columns) are handled.

If you want to control how new instances are created, inherit from BindingList<T> and override AddNewCore().

Marc Gravell