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

查看:164
本文介绍了如何阻止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.

我如何阻止这样做?

我尝试过:


  • 使控件冻结

  • 设置 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天全站免登陆