Say if this is my Data class
class Data
{
public int A { set; get;}
public long B { set; get;}
public string C { set; get;}
}
Now I have a collection of Data
as data source and I want the DataGridView
to bind to it.
But I only want to display A
and C
in the view. What's the easiest way to do this?
CodePudding user response:
Add the columns you want to the grid in the designer. Set the DataPropertyName
of each column to the name of the data source property/column that you want to bind to. Before binding the data in code, set AutoGenerateColumns
to false
, so that the grid doesn't create any extra columns.