开发者

DataGridView bound to custom class

开发者 https://www.devze.com 2023-02-21 06:33 出处:网络
I used this thread\'s answer to bind a DataGridView to a dictionary: DataGridView bound to a dictionary

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

精彩评论

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