简体   繁体   中英

C# array/list into DataGridView Column

my Code looks like this:

public class A
    {
        public string N{ get; set; }

        public int E1 { get; set; }

        public int E2{ get; set; }

        public List<Genre> G{ get; set; }

        [System.ComponentModel.Browsable(false)]
        public string L { get; set; }
    }

and I have a BindingList that contains many of them. Now I want to display this list in a DataGridView, which works pretty good, except that the List inside the A's is NOT shown.

Binding the DataSource:

dgSeen.DataSource = Storage.seen;

the List G gets set after some time, and has the correct value(s). So all what I want is, that there is a 4th DataGridView column that shows me the content of the List like "Action, Fatasy, SciFy" and so on.

I hope you understand what I need, and thanks in advance for every help :)

You can create a computed property for this purpose.

public string GDisplay 
{
    get 
    {
        return String.Join(", ", G);
    }
}

Then use GDisplay in your grid to represent G. Obviously this is a read-only design. If you want to be able to modify the value of G via the grid, you'll have to implement a setter for GDisplay . For example:

    set 
    {
        G = value.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
                 .Select(x => x.Trim())
                 .ToList();   
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM