0

I'm databinding a collection of objects to a datagridview as follows:

    public BindingList<Selection> selections = new BindingList<Selection>();
    dgvSelections.DataSource = selections;
    if (!mainForm.selections.Contains(mySelection))
    {
       mainForm.selections.Add(mySelection);
       mainForm.dgvSelections.Refresh();                        
    }
    else
    {
       int index = mainForm.activeArbSelections.IndexOf(mySelection);
    }

The 'Selection' object looks like this:

public class Selection : INotifyPropertyChanged, IComparable
{

    private Int64 id;
    public Int64 ID
    {
        get { return id; }
        set
        {
            id = value;
        }
    }

    public SortedDictionary<Int64, Quote> quotes = new SortedDictionary<Int64, Quote>();
    public SortedDictionary<Int64, Quote> Quotes
    {
        get { return quotes; }
        set
        {
            quotes = value;
            NotifyPropertyChanged("quotes");
        }
    }

The 'Quote' object looks like this:

public class Quote
{
    public string name;
    public Int64 ID;

When I databind the 'selections' collection to the dgvSelections datagridview, and add selections to the collection, the datagridview show the ID variable in the datagridview, and then just shows the text 'Collection' for the 'quotes' object as a placeholder, or object type or something.

How can I get the datagridview to display this following: for each row (selection) a cell for each quote in the 'quotes' collection showing the name and ID of the quote? In fact, I'd be happy enough with a cell for each quote, and some kind of concatenated text variable showing the name and ID as a string or something. Just in case: different rows (selections) may have a different number of quotes associated with it.

Basically, I can show each selection on a separate row, and have all the relevant variables in that selection diplayed in the datagridview, but am stuck with no way of showing all the quotes in the quotes collection in each of those selections.

I'd appreciate any pointers at all on this. Thanks.

4

1 回答 1

1

这是您必须寻找的 -绑定到源的二级属性

于 2012-09-02T17:49:22.973 回答