esko_user
asked on
Datagridview datasource as List
Hi all, I've a problem with a datagridview.
The data source of the control is a List<Person> mypersonlist ; where Person is type of a class I've
created.
The class (Person) has some properties like Job, Name, Surname and so on.
Now my datagridview is bounded to a collection of Person when i set my data source as mypersonlist:
Datagridview.Datasource = mypersonlist;
Most of properties of the Person class are strings (like Name and Surname),
Now the question is that the class Person have a property (job).
Furthermore I've got mypersonlist collection
The collection contains all possible jobs(for example, Associate, Accountant.. and so on..).
I would like to have a combobox column in my datagridview that shows the current job of
the person and gives the user the chance to change the options between all jobs in the
jobs collection.
How can I do that?
The data source of the control is a List<Person> mypersonlist ; where Person is type of a class I've
created.
The class (Person) has some properties like Job, Name, Surname and so on.
Now my datagridview is bounded to a collection of Person when i set my data source as mypersonlist:
Datagridview.Datasource = mypersonlist;
Most of properties of the Person class are strings (like Name and Surname),
Now the question is that the class Person have a property (job).
Furthermore I've got mypersonlist collection
The collection contains all possible jobs(for example, Associate, Accountant.. and so on..).
I would like to have a combobox column in my datagridview that shows the current job of
the person and gives the user the chance to change the options between all jobs in the
jobs collection.
How can I do that?
Enumerate thru your collection and create a dataset out of it. Consider having a Person DataTable and Job, Name, Surname...etc DataColumns. You may customize DateGridView columns to get Combo view (There are plenty of examples out there, just google). Later bind the DataSet to your DataGridView. That should get what you wanted.
ASKER
My collection is a List which has the object of the class Person, and Person inherits a class PersonData. Person has a property Job and Persondata has the properties like Name, Surname etc. how should i enumerate this list so that the data grid view is filled with the values like,
Job Name surname
Associate Vinod kothari
Accountant
Job Name surname
Associate Vinod kothari
Accountant
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.