的WinForms DataGridView的数据绑定到复杂类型/嵌套属性 [英] Winforms DataGridView databind to complex type / nested property

查看:237
本文介绍了的WinForms DataGridView的数据绑定到复杂类型/嵌套属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想数据绑定一个的DataGridView 到包含的类结构如下列表:

I am trying to databind a DataGridView to a list that contains a class with the following structure:

MyClass.SubClass.Property

当我通过code步骤,在 SubClass中从不要求。

When I step through the code, the SubClass is never requested.

我没有得到任何错误,只是看不到任何数据。

I don't get any errors, just don't see any data.

请注意,我可以在同一层级的编辑表单数据绑定。

Note that I can databind in an edit form with the same hierarchy.

推荐答案

迪米特法。

创建的MyClass的一个公开SubClass.Property属性。像这样:

Create a property on MyClass that exposes the SubClass.Property. Like so:

public class MyClass
{
   private SubClass _mySubClass;

   public MyClass(SubClass subClass)
   {
      _mySubClass = subClass;
   }

   public PropertyType Property
   {
      get { return _subClass.Property;}
   }   
}

这篇关于的WinForms DataGridView的数据绑定到复杂类型/嵌套属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆