开发者

DataGridView bound to custom class

I used this thread's answer to bind a DataGridView to a dictionary:

DataGridView bound to a dictionary

This works fine if I use Dictionary<string, double>, but 开发者_开发百科if I use a class instead of string (Dictionary<MyClass, double>) the DataGridView displays the string representation of MyClass. MyClass has a string property (Value) that I would like to be displayed in the DataGridViwe column. Is there a way to accomplish this?


The simplest method would be to implement ToString() in your class, if this is an option, eg:

public class MyClass
{
    public string Value { get; set; }

    public override string ToString()
    {
        return Value;
    }

    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜