2
votes

I have a winforms that contains a dataGridView. The datagridView contains 4 columns (1 checkbox, and 3 text).

When I load my form, I am loading data in a list of object (almost 15 attributes).

In my columns, I just have 3 values of my Objects that must be displayed, and the others will be use, programmatically, but not visible for the user.

The problem is, when I add the list as the DataSource of my GridView, I got the 3 columns, with values I want, but also 1 columns for each of the others attributes...

Why does the other columns appears, when I do not add them in my code?

I do not found the DataGridView property that will prevent this columns to be add.

3

3 Answers

2
votes

set DataGridView.AutoGenerateColumns to false and bind columns manually by adding columns and setting data property

2
votes

Set AutoGenerateColumns property of DataGridView as false

You can set this by code

datagridview.AutoGenerateColumns = false;
datagridview.DataSource = mydatasource;

Update :

This is property is browsable in ASP.net Gridview but not in WinForms in the designer

That is because this property set as browsable false

read this for more info: Why DataGridView.AutoGenerateColumns has a Browsable(false) attribute applied?

1
votes

Set AutoGenerateColumn to False

dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = dataSource;