简体   繁体   中英

C# DataGridView Binding

I have the following class:

    class Channel
   {
    public int Number { get; private set; }

    public double HighestCoChannelSignal { get; private set; }
    public double HighestOverlappingSignal { get; private set; }

    public List<Network> NetsCoChannel { get; set; }
    public List<Network> NetsOverlapping { get; set; }
   }

I have a list of Channel objects. I want to bind it to a DataGridView and show: Number, HighestCoChannelSignal, HighestOverlappingSignal, NetsCoChannel.Count, NetsOverlapping.Count. And for example if the HighestCoChannelSignal is a special value set the cell value in DataGridView to something I want. How can I achieve this?

You can perform a LINQ query to get the data you want into instances of an anonymous type and bind the result to the grid, eg

var data = channels.Select(c => new {c.Number,
                                     c.HighestCoChannelSignal,
                                     c.HighestOverlappingSignal,
                                     NetsCoChannelCount = c.NetsCoChannel.Count,
                                     NetsOverlappingCount = c.NetsOverlapping.Count})
                   .ToArray();

You can add whatever code is appropriate to deal with that "special value". If you want a specific answer then you'll have to provide a specific description.

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