DataGridView自动生成列 [英] DataGridView automatically generates columns

查看:402
本文介绍了DataGridView自动生成列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



有时我的DataBridView中的列被更新。有时所有属性都以列的形式添加,但现在也删除了所有的列。所以我已经失去了所有的设置。



什么时候可以自动添加列?



m使用VS.NET 2010)



更新:

  // 
//摘要:
//获取或设置一个值,指示是否自动创建列
//当System.Windows.Forms.DataGridView.DataSource或System.Windows.Forms.DataGridView .DataMember
//设置属性。
//
//返回:
//如果要自动创建列,则为true;否则,假。
//默认为true。
[可浏览(false)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
[DefaultValue(true)]
public bool AutoGenerateColumns {get;组;

设计器中没有显示该属性,并且未选中隐藏高级属性。



更新2:
更新实体框架模型时,将再次添加所有列。我只能在窗体的构造函数中设置属性。这是非常讨厌的。

解决方案

我实际上不知道这是什么时候发生的,但我倾向于手动创建所有的列。我在设计器中创建列,并在代码中将 AutoGenerateColumns 属性设置为 false


On my Windows Form I have a DataGridView component, which is bound to a BindingSource. The BindingSource is an object datasource to an EntityFramework object.

Some times the columns in my DataBridView are renewed. Sometimes all properties are added as column, but now it also removed all my columns. So i've lost all my settings.

When to columns get automatically get added?

(I'm using VS.NET 2010)

Update:

//
// 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; }

The property did not show up in the designer, and "hide advanced properties" is not checked.

Update 2: When I update my entity framework model, all columns are added again. I only can set the property in the constructor of the form. This is very annoying.

解决方案

I actually don't know when this happens, but I tend to create all the columns manually. I create the columns in the designer and set the AutoGenerateColumns property to false in my code.

这篇关于DataGridView自动生成列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆