?
Solved

Problem with ancestor on form

Posted on 2008-01-31
9
Medium Priority
?
349 Views
Last Modified: 2008-01-31
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
0
Comment
Question by:ACAE
  • 5
  • 4
9 Comments
 

Author Comment

by:ACAE
ID: 20786230
Do you mean that I have to add the 'If not me.designmode' too ?
0
 
LVL 11

Expert Comment

by:indianguru2
ID: 20787213
yes
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
LVL 11

Expert Comment

by:indianguru2
ID: 20787231
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
 

Author Comment

by:ACAE
ID: 20787700
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
 
LVL 11

Accepted Solution

by:
indianguru2 earned 2000 total points
ID: 20787728
       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
 

Author Comment

by:ACAE
ID: 20787871
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
 

Author Comment

by:ACAE
ID: 20787973
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
 
LVL 11

Expert Comment

by:indianguru2
ID: 20788043
Can you try and remove that grid and add a new grid with the same name?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
Suggested Courses

592 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question