Binding objects DataGridView C#

前端 未结 4 491
南旧
南旧 2020-12-10 08:54

i have a DataGridView and a list of objects that i would like to show.

The Objects are these:

public class Entity
{
    public int ID { get; set; }
}         


        
4条回答
  •  天命终不由人
    2020-12-10 09:46

    Your design is so strange. I have another approach is to override ToString() method of your classes (Service and City) like this:

    public class Service: Entity
    {
      public string Name { get; set; }
      public override string ToString(){
         return Name;
      }
    }
    
    public class City: Entity
    {
      public string Name { get; set; } // Max 50 chars
      public override string ToString(){
         return Name;
      }
    }
    

    And that works OK. Again, your design is a little strange ^_^

提交回复
热议问题