Winforms DataGridView databind to complex type / nested property

前端 未结 4 1711
余生分开走
余生分开走 2020-12-03 14:52

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

MyClass.SubClass.Property

4条回答
  •  死守一世寂寞
    2020-12-03 15:07

    Law of Demeter.

    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;}
       }   
    }
    

提交回复
热议问题