Problem with ancestor on form

Hello,
I have created an ancestor datagrid (inherits from datagrid), which I use to put on forms. Hovewer, I have a problem with Vb.net 2005 : it gives an error when I open the form, and when I have changed the code and save, it changes the code back to what is was and gives an error again.

This is the situation:
- I have put the datagrid on my form, DGROUTE, and linked a dataview to it
- Each time I open the form, I get the error 'Datagrid received an exception at design time. Reset the datasource and Datamember property on the grid'.
- I reset the datagrid
- I immediately get the error 'Name 'dgRoute' is not declared
- I then check my code, and see that vs.net has declared the dgRoute as a local variabel in the 'InitializeComponent' function
- I change it to 'Friend WithEvents dgRoute As YnpClasses.YnpDataGrid', and ad the line 'Me.dgRoute = New YnpClasses.YnpDataGrid' -> The errors disappear
- I go back to the design of the form, and get the same error again: 'Datagrid received an exception at design time. Reset the datasource and Datamember property on the grid'.
- I reset the datagird
- I immediately get the error 'Name 'dgRoute' is not declared
And so on and so on.

I didn't have this problem in vs.net 2003. It seems that vs.net 2005 changes my code incorrectly. I think it is to stupid to do so. It there a way to stop this from happening ? On other forms, this problem also appears but it doesn't change my code
ACAEAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ACAEAuthor Commented:
Do you mean that I have to add the 'If not me.designmode' too ?
0
indianguru2Commented:
yes
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

indianguru2Commented:
The problem with A User Control is that it doesn't know when the form is called (in Design/Run mode).
So if you write any code on Load / Init which can only work when it is in Run mode, it will crash.
So you have to tell the Control whether its in Design Mode or Run Mode.
0
ACAEAuthor Commented:
I have replaced the code in the New() function of the form to:

Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        If Not Me.DesignMode = True Then
            InitializeComponent()
        End If

        'Add any initialization after the InitializeComponent() call
    End Sub

But this doesn't change the error. Do I have to put other code in the designmode ?
0
indianguru2Commented:
       If Not Me.DesignMode = True Then
            InitializeComponent()
        End If
Never do that ... that won't initialize it in designmode ...

have you written anything in InitializeComponent or Load or Init
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ACAEAuthor Commented:
OK, changed this back. I have checked the form Load, Paint, Init, .. event, and changed all the code. I also dit this on the ancestor, but the problem remains. I also checked all the code of all my ancestor objects, and changed some code and: HURAY!! This works fine now.µ

Thank you very very much for you help
0
ACAEAuthor Commented:
I was a little bit too fast: .Net still changes my code, so this is now the current situation:

This is the situation:
- I open the form with the datagrid on it, and get no error
- when I save the form, I get the error 'Name 'dgRoute' is not declared
- I then check my code, and see that vs.net has declared the dgRoute as a local variabel in the 'InitializeComponent' function (**)
- I change it to 'Friend WithEvents dgRoute As YnpClasses.YnpDataGrid', and ad the line 'Me.dgRoute = New YnpClasses.YnpDataGrid' -> The errors disappear
- Now the form is OK, I close it
- When I reopen it, the problem occurs again. It changes the code (**) again, so I have to reset it.
The strange thing is: this only happes for 1 form, all the other forms I checked are OK.
0
indianguru2Commented:
Can you try and remove that grid and add a new grid with the same name?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.