I use LINQ to query my MSSQL 2005 database. I want to show several fields of some tables in one DataGridView. The selection of a row of the DataGridView should result in showing results in another DataGridView based on a column which is not shown in any DataGridView (it is an ID attribute).
What is a good way to accomplish this?
My Ideas of Possible Solutions
Bind to an Anonymous Type
I would bind my DataGridView to a BindingSource, which is bound to the result of an anonymous LINQ query (anonymous type). To get the ID to build up the relation to the second DataGridView, I would use reflections.
Bind to a Specific Type
I would create a class which holds all fields I want to show in my DataGridView and additionally the ID field. The BindindSource would bind to an instance of this specific class.
I want to avoid this method, because I would have to create one class for each DataGridView I use in my application and I would have to maintain three parts, the class, the LINQ query and the DataGridView columns.