I am trying to bind my objects by columns in the datagridview component but I could not find any way to do it.
This is an example of what I am trying to achieve.
I have the Emp class
public class Emp
{
public int ID { get; set; }
public string Name { get; set; }
public string City { get; set; }
public Emp(int id, string name, string city)
{
this.ID = id;
this.Name = name;
this.City = city;
}
}
and an array of Emp
var arrEmp = new[] {
new Emp( 1, "Devesh Omar", "Noida"),
new Emp( 2, "Roli", "Kanpur"),
new Emp( 3, "Roli Gupta", "Mainpuri"),
new Emp( 3, "Roli Gupta", "Kanpur"),
new Emp( 3, "Devesh Roli ", "Noida"),
};
When I bind the data to the grid
dataGridView1.DataSource = arrEmp;
I get this (which is ok)
I would like that the grid has only 3 fixed rows (Id, Name, City) and the column all the values. (the matrix transpose) Also, if I add or remove an element to/from arrEmp, that the element will be added as a column.
The example was taken from here

