自定义DataGridView窗体设计器自动生成列问题

自定义DataGridView窗体设计器自动生成列问题

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

问题描述

问候所有,

我没有找到任何关于这个问题的参考,所以我想我会尝试提交你的集体智慧。

我要问:
我在自定义表单控件库中有一个C#类,它从DataGridView继承(间接)。此自定义DataGridView旨在允许编辑具有许多复杂关系的特定类型的业务对象(即,显示显示通过桥接表等相关的对象的Name属性的ComboBox)。由于它的目的是相当有限的,我使用VS2008设计器明确指定列并设置AutoGenerateColumns = false(当然希望我知道为什么这个属性仅在运行时可用)。

一切正常,直到我打开包含WinForm的设计者。此时,IDE似乎会自动生成自定义DataGridView中所有(已指定)列的副本。由于某些原始列(通常是DataGridViewComboBoxColumns)需要选项的运行时数据绑定,因此应用程序会在将网格绑定到"无效组合框值"时爆炸。错误等(因为组合框列的副本没有填充任何项目。)

我可以通过手动编辑表单的< 表单名称>暂时解决此问题。 .designer.cs文件,但是,一旦我重新打开表单的设计器,我的所有手工编辑都会被覆盖,我回到我开始的地方。

有谁知道如何压制自动 - 由表单的设计者生成列?

提前感谢...

解决方案

Greetings All,

I've had no luck finding any reference to this problem so I thought I'd try submitting to your collective wisdom.

To whit:
I've got a C# class in a custom forms control library that inherits (indirectly) from DataGridView. This custom DataGridView is designed to allow for editing of a specific type of business object with a number of complex relationships (i.e., to show ComboBoxes displaying the Name property of objects related via bridge tables and the like). Since it's purpose is fairly constrained, I used the VS2008 designer to explicitly specify the columns and set AutoGenerateColumns = false (sure wish I knew why this property is only available at runtime).

All works fine, until I open the designer for the containing WinForm. At that point, the IDE seems to auto-generate copies of all of the (already-specified) columns in the custom DataGridView. Since some of the original columns (the DataGridViewComboBoxColumns, usually) require run-time data binding of options, the app blows up upon binding the grid with "Invalid Combo Box value" errors and the like (since the copies of the combo box columns have no items populated).

I can fix this, temporarily, by manually editing the form's <form name>.designer.cs file, but, as soon as I re-open the form's designer, all my hand-editing is overwritten and I'm back where I began.

Does anyone know how to suppress the auto-generation of columns by the form's designer?

Thanks in advance...

解决方案


这篇关于自定义DataGridView窗体设计器自动生成列问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 14:45