DataGridView自动生成列

Boj*_*ojo 10 c# datagridview visual-studio-2010

在我的Windows窗体上,我有一个DataGridView组件,它绑定到BindingSource.BindingSource是EntityFramework对象的对象数据源.

有时我的DataBridView中的列会被更新.有时,所有属性都会添加为列,但现在它也会删除所有列.所以我丢失了所有设置.

什么时候列自动添加?

(我正在使用VS.NET 2010)

更新:

//
// Summary:
//     Gets or sets a value indicating whether columns are created automatically
//     when the System.Windows.Forms.DataGridView.DataSource or System.Windows.Forms.DataGridView.DataMember
//     properties are set.
//
// Returns:
//     true if the columns should be created automatically; otherwise, false. The
//     default is true.
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
[DefaultValue(true)]
public bool AutoGenerateColumns { get; set; }
Run Code Online (Sandbox Code Playgroud)

该属性未显示在设计器中,并且未检查"隐藏高级属性".

更新2:当我更新我的实体框架模型时,将再次添加所有列.我只能在表单的构造函数中设置属性.这非常烦人.

Tho*_*mar 5

我实际上不知道何时发生这种情况,但我倾向于手动创建所有列.我在设计器中创建列,并在我的代码中将AutoGenerateColumns属性设置为false.


Kis*_*mar 5

添加此代码或将DataGridView属性更改AutoGenerateColumns为false

DataGridView1.AutoGenerateColumns=false;
Run Code Online (Sandbox Code Playgroud)

  • 请参阅我的问题的更新。我还不能回答问题。 (2认同)