2

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.

4

3 回答 3

2

AutoGenerateColumnsDataGridView 的属性设置为false

您可以通过代码设置

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

更新 :

此属性在 ASP.net Gridview 中可浏览,但在设计器中的 WinForms 中不可浏览

那是因为这个属性设置为 browsable false

阅读此内容以获取更多信息: 为什么 DataGridView.AutoGenerateColumns 应用了 Browsable(false) 属性?

于 2013-07-18T09:53:35.487 回答
2

通过添加列和设置数据属性手动设置DataGridView.AutoGenerateColumns和绑定列false

于 2013-07-18T09:52:17.637 回答
1

AutoGenerateColumn设置为False

dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = dataSource;
于 2013-07-18T09:53:02.807 回答