开发者

Datagridview shows classname instead of property

I'm trying to put data in a datagridview by putting a List as the datasource. This works great, however, nested classes are listed as shown on the screenshot. I'd like to show on开发者_运维百科ly 1 property of those classes.

http://i.imgur.com/Cw6LY.png

Is there a way I can do this? I don't really know what to search for..


Just override ToString to show what you need.

Unless you want editing, which will require more effort.

Update:

A simple solution (if you do not have 10's or 100's of these) is to create a proxy class.

Example:

class FooProxy
{
  Foo bar; // internal object

  public string Baz 
  {
    get {return bar.Baz; } 
    set { bar.Baz = value }
  }

  public bool Oink
  {
    get {return bar.Oink.Enabled; } 
    set {bar.Oink.Enabled = value; }
  }
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜