English 中文(简体)
Bind a GridControl to a SortedList
原标题:Bind a GridControl to a SortedList

I am trying to have a table (a DevExpress GridControl in particular) be bound to a SortedList. I want the first column of the table to be bound to the Key of the SortedList and the second column to be bound to a field of the object in the key of the SortedList, for example,

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        InitializeTable();
    }

    public void InitializeTable()
    {
        SortedList<DateTime, Dividend> EquityDividends = new SortedList<DateTime, Dividend>();

        EquityDividends.Add(new DateTime(2011, 1, 12, 16, 30, 00, DateTimeKind.Local), new Dividend(new DateTime(2011, 1, 12, 16, 30, 00, DateTimeKind.Local), "120", 12, new TimeSpan(4, 0, 0)));
        EquityDividends.Add(new DateTime(2011, 1, 13, 16, 30, 00, DateTimeKind.Local), new Dividend(new DateTime(2011, 1, 12, 16, 30, 00, DateTimeKind.Local), "125", 12, new TimeSpan(4, 0, 0)));

        gridControl1.DataSource = new BindingSource() { DataSource = EquityDividends };

        bandedGridView1.Columns[1].FieldName = "ExpectedDividend";
    }
}

public class Dividend
{
    public DateTime InDividendDate;
    public string ExpectedDividend;
    public double Adjustment;
    public TimeSpan TimeRemaining;

    public Dividend(
        DateTime InDividendDate,
        string ExpectedDividend,
        double Adjustment,
        TimeSpan TimeRemaining)
    {
        this.InDividendDate = InDividendDate;
        this.ExpectedDividend = ExpectedDividend;
        this.Adjustment = Adjustment;
        this.TimeRemaining = TimeRemaining;
    }
}

This doesn t quite work (the key comes up in column 0 and a string "WindowsFormsApplication10.Dividend" comes up in column 1). Does anyone have any suggestions?

问题回答

仅高于以下方法:<代码> 类别> 分类代码> 分配,并退还您希望的价值:

public override string ToString()
{
    return "MyValue";
}

页: 1





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签