datagridview how do I set columns and settings after binding to a list of objects?
Posted on 2013-09-07
I have a ton of dataviews bound to lists of objects.
I don't need all columns so I do things like
var data = (from item in AllItems
grid.datasource = data;
This works well for testing purposes but I need to make the grids look a little nicer. For example, some grids could have ID columns I don't want shown.
I am looking for a way to make a central area to define my grids so I can reuse the layout. For example, I could have a
public static void CreateGridItems(DataGridView dgv)
I'm wondering what is the best way to setup a grid if I want to through code? Is my example above good? Is there some pattern I should follow, or a better way to do this? Since I will want to set column width, hide columns etc, so I am not just looking for a subclass of my main object. The goal is to setup the grid, not just filter out columns.