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

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

问题描述

我正在尝试将 DataGridView 数据绑定到包含具有以下结构的类的列表:

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

MyClass.SubClass.Property

当我逐步执行代码时,从不请求 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天全站免登陆