【发布时间】:2012-03-19 10:07:48
【问题描述】:
在我的 Windows 窗体上,我有一个绑定到 BindingSource 的 DataGridView 组件。 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; }
该属性未在设计器中显示,“隐藏高级属性”未勾选。
更新 2: 当我更新我的实体框架模型时,所有列都会再次添加。我只能在表单的构造函数中设置属性。这很烦人。
【问题讨论】:
-
将DataGridView的AutoGenerateColumns属性设置为false。
-
我在表单构造函数中设置了 AutoGenerateColumns = false 但仍然遇到问题
-
在我的例子中,这些顽皮的自动生成的列只出现在设计器中,而不是实际的表单上。看起来像一个错误。
-
这里也一样,每当我使用 datagridview 重新打开表单时,它都会从有界源生成所有列。
标签: c# visual-studio-2010 datagridview