Form doesn't initialize all controls

Adagio

Well-known member
Joined
Dec 12, 2005
Messages
162
Programming Experience
Beginner
I have a weird problem with one of my forms, and I can't seem to find where the problem occurs

On my form I have 3 group boxes with controls and several controls outside these group boxes. Now and then something happens during startup of the form, causing the controls outside the group boxes to never load. When this happens the program never executes the code in the form-load box
It's difficult to say how often this happens as it's completely random, sometimes you can start the program on new 20 times in a row without any problems, and sometimes you get the problem twice in a row

The form that causes the problem is not the main form, but a form opened by clicking on a toolstripmenuitem


I tried to add some breakpoints in the form.designer code, but during the ~40 tests I did during this time, the bug never showed, but as soon as I removed the breakpoint it happened again
 
I have not seen this happen in VS2005, but did see similar things in VS2003 sometimes. When you experience such irrational behaviour it is best to try update software, SP1 updates are available for all Studio 2005 versions here: http://msdn.microsoft.com/vstudio/support/vs2005sp1/default.aspx

You could also post an attachment project here that feature the problem and see if others get same problem or figure it out.
 
Nobody who has any idea what could be wrong here?

The inference was for you to install VS-SP1 and see if the problem went away.. If you dont want to install it, create an example verison of your project and I'll run it on my SP1 system
 
I installed SP1 yesterday, so I'll do some testing today to see if it still happens or not

It still happens, I'll try to create a new project with just the form that causes the problem
 
I can't seem to replicate the problem in a new project, and it's not possible to give you a copy of the current project
I might have to try to remake the form from scratch to see if that fixes the problem

And right now I have another problem with form controls on another form. It's not exactly the same problem, the problem is that whenever I add a control on the form (a different form) I get the following error when trying to view form design: "Object reference not set to an instance of an object. ", which makes it impossible to view the form. Only way to get back to viewing the form is is by manually remove the new control in the form designer code
It doesn't seem to matter which control I add, textbox, datepicker, label... they cause the problem

I guess I need to remake both these forms

Edit: I had the same problem when I tried to delete an item from the form using the form designer, I had to remove the control through the designer code to avoid the problem
 
I've never seen any of those happen also.
 
Ive seen a few problems manifest with the froms designer - if you drop items from a dataset onto a form, and then change the dataset, it can really screw up the form designer.. Object ref not set, i get in the dataset designer from time to time, but I know why it occurs..

Remake the forms, with SP1's designer, and see how it goes.. Also keep a copy of the damaged forms and see if you can compare them
 
I might have found the problem, but I don't have a solution

The problem looks like it has something to do with my class CurrencyTextbox that inherits Textbox

The CurrencyTextbox works fine during runtime, but apparently they are the ones who causes the problem (deleting all of those controls from my form made it possible to add more controls through the designer)
Now that I know where the problem is I might find a solution somewhere
 
I just copied the code from my CurrencyTextbox into a different project, here it worked without any problems

Edit: While creating a new class that inherits Textbox and pulling it onto the form works just fine
 
Ok, this makes no sense at all. I just created a new class (in the same project where CurrencyTextbox failed) to test where in my code it goes wrong.
I copied one method at a time into this new class until both classes were exactly the same. During this time CurrencyTextbox didn't work, but now when both classes are the same, all of the sudden CurrencyTextbox seems to work!?!
 

Latest posts

Back
Top