问题描述
我创建了一个自定义数据网格控件.我将它拖到 Windows 窗体上并设置它的属性,如 column 和 all &运行该项目.它构建成功,我可以在表单上查看网格控件.
I have created a custom data grid control. I dragged it on windows form and set its properties like column and all & ran the project. It built successfully and I am able to view the grid control on the form.
现在,如果我尝试在设计器中查看该表单,我会收到以下错误..
Now if i try to view that form in designer, I am getting following error..
Object reference not set to an instance of an object.
Instances of this error (1)
1. Hide Call Stack
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.GetMemberTargetObject(XmlElementData xmlElementData, String& member)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.CreateAssignStatement(XmlElementData xmlElement)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.XmlElementData.get_CodeDomElement()
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.EndElement(String prefix, String name, String urn)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.Parse(XmlReader reader)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.XML.CodeDomXmlProcessor.ParseXml(String xmlStream, CodeStatementCollection statementCollection, String fileName, String methodName)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomParser.OnMethodPopulateStatements(Object sender, EventArgs e)
at System.CodeDom.CodeMemberMethod.get_Statements()
at System.ComponentModel.Design.Serialization.TypeCodeDomSerializer.Deserialize(IDesignerSerializationManager manager, CodeTypeDeclaration declaration)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)
如果我忽略该异常,表单将显示为空白,上面没有网格控件的迹象.但是我可以在设计器文件中看到网格的代码.
If I ignore the exception, form appears blank with no sign of grid control on it. However I can see the code for the grid in the designer file.
任何关于此的指针都会有很大帮助.
Any pointer on this would be a great help.
我已经为我的自定义要求自定义了网格,例如我添加了自定义文本框.我定义了 3 个构造函数
I have customized grid for my custom requirements like I have added custom text box n all. I have defined 3 constructors
public GridControl()
public GridControl(IContainer container)
protected GridControl(SerializationInfo info, StreamingContext context)
推荐答案
我一直有这个问题......太糟糕了.
I have this problem all the time...it sucks.
[漫步(开启)]
以下是我认为我知道的:
Here is what I think I know:
- 在设计时将控件放置在表单上.经常构建和刷新..这会让你知道是什么变化导致设计师吐槽.
- 一直关闭 Visual Studio 并重新打开....我无法告诉您我追查了多少次设计师错误是设计师被卡住"了.
- 理解这一点非常重要:设计师真的非常愚蠢......就像一袋石头一样愚蠢.
自定义对象类型的任何公共字段或属性几乎总是会导致设计者混淆*.我发现以下属性可以解决大部分问题:
- When designing place the control on a form. Build and refresh often..this will let you know what change caused the designer to barf.
- Close visual studio all the way an re-open....I cannot tell you how many times I have chased a designer error that was the designer being "stuck".
- It is very important that you understand : The designer is really, really stupid...like bag of rocks stupid.
Any public fields or properties of custom object types will almost always cause designer confusion*. I find the following attributes will clear up most of these problems:
[可浏览(假)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
没有默认构造函数的公共字段或属性总是会导致设计者混淆.当您将用户控件放在表单上时,设计器会有效地创建控件.所以任何公共对象都需要一个清晰的创建路径.我发现解决这个问题的最简单方法(阅读技巧)是将非平凡的自定义类保持私有并将公共属性公开为外观.
Public fields or properties without a default constructor will always cause designer confusion. When you drop a user control on a form the designer effectively creates the control..so any public object needs a clear creation path. I have found that the easiest way around this (read hack) is keeping the non-trivial custom classes private and expose public properties as a facade.
-- 我是否说重新启动 Visual Studio 是因为有时设计师会卡"在一个不存在的错误上?..我希望我做到了.
-- Did I say restart visual studio because sometimes the designer is "stuck" on an error that doesn't exist ?..I hope I did.
[漫步(关闭)]
我希望这能有所帮助..
I hope some of this helps..
*设计师困惑:设计师没有显示您的控件,而是向您显示了一个无用的错误消息,可能包含也可能不包含它正在保护您免受代码丢失的可怕警告......等等,等等.
*designer confusion: Instead of showing your controls the designer shows you a useless error message that might or might not include the dire warning that it is protecting you from code loss...blah, blah.
这篇关于VS 2008 设计器和用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!