Monday, February 21, 2011

Binding a Dictionary to the DataGridView in C#?

I have a dictionary item as below

Dictionary<string, List<StrikePrice>>

where

public class StrikePrice
{
    public string Strike { get; private set; }
    public string Price { get; private set; }

    public StrikePrice(string strike, string price)
    {
        Strike = strike;
        Price = price;
    }
}

and I wish to assign this dictionary to the DataGridView

this.dataGridViewTest.DataSource = listSmiles;

I understand that a dictionary can't be assigned to the the datasource as this doesn't derive from the IList interface.

Is there any way I can assign this dictionary element to the datagrid?

From stackoverflow
  • If the question relates to WPF or silverlight, this article gives a solution.

    I've been using it and it performs well, even for large numbers of columns.

    tush1r : @Phillip: This is for Winforms application.
  • Have you tried using the Values property of the Dictionary?

    this.dataGridViewTest.DataSource = listSmiles.Values
    
    tush1r : @Kane: I tried doing this, however this didn't work.

0 comments:

Post a Comment