你怎么prevent在一个DataGridView的Visual Studio设计自动生成的列? [英] How do you prevent the Visual Studio designer auto-generating columns in a DataGridView?

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

问题描述

我产生我在一个子类 DataGridView中的所有列编程。但是Visual Studio 2008中保持阅读我的构造函数的类(其中填充一个数据表空的内容,并将其绑定到的DataGridView )并生成code在的InitializeComponent 法的列 - 在这个过程中设置的AutoGenerateColumns

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.

这导致在设计时编译错误而只通过手动进入设计code和删除所有引用到这些自动生成的列解决。

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 实例化对象保护(其中提到的本网站
  • 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).

这篇关于你怎么prevent在一个DataGridView的Visual Studio设计自动生成的列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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