Hello i have a linq query as follow
var q = (from c in db.table1
select c).ToList();
then i assign the result to a DataGridView
myDGV.DataSource = q;
the table1 before have: myCol1,myCol2,myCol3 columns
the grid view will present the data as it is with the same columns names as the db table
the question is where did it get the names?
i just assigned a collection to its data source nothing more
Are you using an entity model? If so when you create your model it generates classes for each table including properties which match all of the table columns from the database. When you set the DataSource to a list of these objects it will automatically assign the property name to the grid view as well.
You can use the HeaderText property of the DataGridView to specify custom text for the column headers if the properties aren’t to your liking:
MSDN Article