I tried creating a gridview by typing code using another block of code on a different page as an example. I found that, when I ran the program and clicked the Edit button on a row, the fields did not change into textboxes for editing. I did have code to handle the Row Editing event.
In an earlier project I found that I had to double-click the Row Editing event in the Properties window for a gridview to create the event handling code. Typing in that code in the separate aspx.cs file did not work.
I am working with ASP.Net / C#.
What is going on with Visual Studio when I do drag and drop from the control menu as opposed to just typing in code? I am assuming it is adding something that I am missing when I am just typing.
Does anyone else have other examples that didn't work when they typed code that I should watch out for?
Even if you did a mighty good job copying the HTML, you likely still missed a few properties. That's because the GridView component comes with a bunch of so-called Design-Time properties that can (only) be configured from the Properties panel in Visual Studio.
I think you'll find that dragging a control from the toolbox onto your web form will set the control's design-time properties to a specific set of default values. This does not happen when you type the HTML by hand.
After several days of happily hacking away on this C# app using Visual Studio 2008, I get struck by a barrage of error dialogs showing:
Code generation for property 'valueMember' failed.
Error was: 'Object reference not set to an instance of an object.'
This happens now often when I make a tiny change in the designer, e.g. shift a control a few pixels, and then try to save. Several such error dialogs appear each second, keeping me busy cancelling all those by hammering the Enter key while trying to get alt-F4 to get VS to close.
Eventually I do get VS to close and to save the changes I made. After restarting VS, I do "clean" on the entire project, then "build" and everything works fine, the app runs fine, no problems.
Until I make another slight change in the form designer.
I don't know about any property valueMember in my app.
This makes me crazy, it is a real showstopper for my project. Any help is appreciated.
Try to Close and reopen the Visual Studio. maybe it seem silly, but it works!!
You can debug the designer using another visual studio and attach to process. If you got exception it should be easy to find it that way.
In general when openning the designer the constructor and of course initializeComponent is running.
As this is happening at design time, it is likely that you have a custom control which requires a parameter or other value which does not have a default.
When in design view in Visual Studio; a control instance is created to render it on the visual editor, but if the control requires a property to be set before it can be rendered, it will result in an error.
Can you check that all custom controls have default values, and anything referenced in the constructor that cannot have a default is wrapped by DesignMode property - see http://msdn.microsoft.com/en-us/library/system.componentmodel.component.designmode.aspx.
Similiar to #Chanipoz's answer (close/re-open) my component-rich/user-controls-everywhere forms app started to compile happily after I closed down the main form designer window.
I've had this code stack for years and have never seen the error until today. Not sure where it's coming from. But, something today about having the form open in the designer made everything unhappy. Simply closing it off of the screen made it all go smooth.
Use another instance of Visual Studio to attach to the first instance of visual studio.
Go to Debug-> Attach To Process and look for the devenv.exe process. Since you'll have two devenv.exe processes running you'll probably want to pick the one with the lower ID, that's usually the first instance of visual studio that was run.
I had to face this problem. As I have found the solution below
I am facing this issue in my customized control.
we need to implement like this
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public MyCustomclass _Prperty { get; set; }
I had to face this problem. As I have not found the solution (much inheritance), I can tell:
.SuspendLayout() and .ResumeLayout() may be missing in code or one of them. The same is with .BeginInit() and .EndInit(). It is expected between them, that there will be = new ... and some settings for properties. Maybe someone facing this problem would find the solution with this information.
The problem is missing initialization code for a public property on the control. This will be added for you when you add the control to the designer, but if you replace a control with a derived control, or update the component, then the designer does not know how to deal with this.
If you have a control (wincontrol) with a public property PropertyA, and you add it to a form (myForm), then the designer will add all the necessary initialization for properties into myForm.Designer.cs. Something like;
Wincontrol1.PropertyA = new List<widget>();
It is not uncommon to need to modify a control slightly, lets say we have a new control MyWinControl
public partial class MyWinControl : WinControl
{
public List<wodget> PropertyDer1;
protected List<wodget> PropertyDer2;
}
If you sub this new control for the old control in myForm.Designer.cs, then you may well encounter this issue. The reason is that PropertyDer1 has no initialization in the winforms designer. PropertyDer2 won't cause any issues because it is protected. Similarly if you had a custom component and you add a new public property after the component has been added to a form.
If however, you deleted the instance of WinControl on the form, and dragged an instance of the MyWinControl onto the form instead, the proper initialization would occur and you would not see the error. The designer will have created the new control like this
Wincontrol1.PropertyA = new List<widget>();
Wincontrol1.PropertyDer1= new List<wodget>();
There are two easy solutions that do not require hiding the property from the designer.
1. If the property doesn't need to be public, give it the right modifier
2. If the property does need to be public, then just edit the code in the myForm.Designer.cs as in the code above to add the missing initializer
If could be of help I just detected a case that brings that same error message, impossible to take away :
I am developing an application in French, and I had to create a ToolStripMenuItem with an accented word in it like "annulées".
The system generated a menu item like "annuléesToolStripMenuItem" and the accent is the culprit.
Enough to delete the item, create it again in English and the just change the Text property of the menu item.
Hope it will be of some help.
I have an issue where the Visual Studio (2010) WinForms designer creates some controls (or at least their fields) globally in the designer file, and some inside the InitializeComponent method called from the constructor.
Does anybody know why the designer creates them locally in the method rather than globally and is there a way to stop it doing this?
It does this on some forms but not all and seems to only really happen to Label controls. The developers of the forms affected are sure they have done nothing differently.
I could fix this manually but would rather know the root of the problem. I need to be able to access the fields from another method which uses reflection to access the fields.
There is a Generate Member (in code, GenerateMember) property that controls whether the control has a member field. (Not too surprisingly, hopefully). It should default to true, but may have been set to false somehow.
I've currently got custom control that has somehow lost its parent and is now not parented to anything but it's still in the list of controls in the form designer. The delete button also doesn't work and is thus disabled. This happens every now and again and its a pain to go through the designer code and remove manually, plus there are other developers that this will annoy and may confuse them.
I'm therefore trying to add a Verb within the controls ComponentDesigner to delete itself from the form. But I realised that because its not 'childed' to anything, it therefore cant be removed as a child. How would I therefore go about deleting a control from the form designer via code?
This can happen when one of your controls throws an exception at design time. That's rarely a silent event, the designer shows a popup message box. Not getting a message box may happen when you swallow exceptions in your code with a try/catch.
Trying to fix this by hacking a designer just adds to the problem. Fix it by editing the designer code, it is okay when you know what you're doing. If you can't find the reason then get it to a point where you can make it somewhat reproducible. Then start another instance of Visual Studio, Tools + Attach to Process and select the first instance. Debug + Exceptions, tick the Thrown box for CLR exceptions so the debugger will stop when the exception is thrown.
Back up the file.
Open up the designer file; e.g., Form1.Designer.cs
Expand this region: Windows Form Designer generated code
You should be able to find your control in the code and delete it. Be careful.
I solved the issue by finding the loose controls within the Document Outline tab. This way is super easy and is graphical.
I'm getting alot of issues lately in a project im working on with databinding. When im about to display a certain form that has bindings inside its controls, the .Show method throws expcetions regarding the binding - "Cannot bind to property or column on datasource. Parameter name: dataMember.".
Now, I'm quite aware this is a rather generic error message, but i can't find a decent way to get any info on which binding failed, which control, which data source/member and so on.
Is there a good way to find this?
I guess some general debugging tips will help:
When debugging, is there an inner exception with more information?
Another tip is to turn on 'Show external code' in the stack trace window. This will allow you to go further down into the stack to the .Net Framework code itself. Turn on your locals window for information on the content of the current context, this might lead you to the problem.
Also be sure to turn on 'Break on exception' for all CLR exceptions.
Good luck.
Well, I'm stumped. One of the controls in the form is a UserControl i made, Which contains some bindings in it.
This used to work fine. Now, I've added inhertience from IEnumerable to my control so it can return certain objects inside it for a different feature i tried adding. Now, If i 'Step-Into' the .Show call, I reach the IEnumrable implementation i made in a certain case.
Although it returned an empty collection at this time, since i had no elements to return, That apparently caused the ArgumentException that i got with the DataBinding for some reason. The moment i remove the IEnumrable inheritence from my control, Everything is back to normal.
I'm completely clueless as to why this happened.