如何防止 Visual Studio 设计器在 DataGridView 中自动生成列? [英] How do you prevent the Visual Studio designer auto-generating columns in a DataGridView?

查看:18
本文介绍了如何防止 Visual Studio 设计器在 DataGridView 中自动生成列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以编程方式在子类 DataGridView 中生成所有列.然而,Visual Studio 2008 不断读取我的构造函数类(它用空内容填充 DataTable 并将其绑定到 DataGridView)并为 InitializeComponent 中的列生成代码 方法 - 在过程中将 AutoGenerateColumns 设置为 false.

I generate all my columns in a subclassed DataGridView programmatically. However Visual Studio 2008 keeps reading my constructor class (which populates a DataTable with empty content and binds it to the DataGridView) and generates code for the columns in the InitializeComponent method - in the process setting AutoGenerateColumns to false.

这会导致设计时编译错误,只能通过手动进入设计代码并删除对这些自动生成的列的所有引用来解决.

This causes errors in design-time compilation which are only solved by manually going into the design code and deleting all references to these autogenerated columns.

我怎样才能阻止它这样做?

How can I stop it doing this?

我试过了:

  • 使控件冻结"
  • 设置 DataGridView 实例化对象 protected(在前一篇文章中提到了 本网站)
  • Making the control 'Frozen'
  • Setting the DataGridView instantiated object protected (suggested in a previous post which referred to this site)

推荐答案

这听起来像是在构造函数中添加控件.也许稍后添加列 - 可能类似于覆盖 OnParentChanged;然后,您将能够检查 DesignMode,以便您只在执行期间(而不是在设计期间)添加列.

It sounds like you are adding controls in the constructor. Perhaps add the columns slightly later - perhaps something like overriding OnParentChanged; you'll then be able to check DesignMode so you only add the columns during execution (not during design).

这篇关于如何防止 Visual Studio 设计器在 DataGridView 中自动生成列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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