Saber Amani
Saber Amani

Reputation: 6489

Binding DataGridView to an specific object

I'm trying to create a custom DataGridView control which is inherited from DataGridView. In this case, this control will be used only for one reason (for example to display list of employees) where we need to display a list of employees in our projects, grid has its own model, the thing what I want is to bind DataSource only to type of List<Employee> not anything else.

Any advice will be helpful.

Upvotes: 0

Views: 171

Answers (1)

alex
alex

Reputation: 12654

In your custom class, you can write you own DataSource property with needed type, using new modifier. That way users of your class will see it typed.

class CustomGrid: DataGridView
{
   public new List<Employee> DataSource 
   {
          get { return (List<Employee>)base.DataSource;}
          set { base.DataSource = value;}
   }   
}

Upvotes: 2

Related Questions