Ancestor datagrid problem

Hello,

I have created a datagrid that inherits from DataGrid:

Public Class YnpDataGrid
    Inherits DataGrid

I'm having strange problems with this ancestor; when I try to open it in the designer, it doesn't display my class but shows a form with the error 'The variable 'ex' is either undeclared or was never assigned'
I have checked my code, and I only use the 'ex' variable in the 'Try' functions:

Try
   ... some code
Catch ex As Exception
     MsgBox(ex.Message)
End Try

This seems to be a very stupid error, but then, vb.net 2005 is the worst development language I have ever encountered (and I have encountered a lot of them).
Anyone knows how to solve this ? I can of course remove the 'try' functions, but then my program could crash without me knowing what is going on.

Thx for your help
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.

indianguru2Commented:
Try
If not me.designmode = true
   ... some code
end if
Catch ex As Exception
     MsgBox(ex.Message)
End Try
0
ACAEAuthor Commented:
I have tried

Try
If not me.designmode = true
   ... some code
end if
Catch ex As Exception
     MsgBox(ex.Message)
End Try

and

If not me.designmode = true
Try
   ... some code
Catch ex As Exception
     MsgBox(ex.Message)
End Try
end if

And I still have teh same error
0
indianguru2Commented:
What have you added in New()
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

ACAEAuthor Commented:

    Public Sub New()
        MyBase.New()

        'This call is required by the Component Designer.
        InitializeComponent()

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

Private Sub InitializeComponent()
  If Not Me.DesignMode = True Then
        'Try

        Me.cmDataGrid = New System.Windows.Forms.ContextMenu
        CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'YnpDataGrid
        '
        Me.ContextMenu = Me.cmDataGrid
        CType(Me, System.ComponentModel.ISupportInitialize).EndInit()

        miColumns = New MenuItem

        cmDataGrid.MenuItems.AddRange(New MenuItem() {miColumns})

        miColumns.DefaultItem = True
        miColumns.Index = 0
        miColumns.Text = "Columns"

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End If
0
indianguru2Commented:
You don't need the Try Catch Block in InitializeComponent
Remove that ...
and keep the me.designmode

Private Sub InitializeComponent()
  If Not Me.DesignMode = True Then
        Me.cmDataGrid = New System.Windows.Forms.ContextMenu
        CType(Me, System.ComponentModel.ISupportInitialize).BeginInit()
        '
        'YnpDataGrid
        '
        Me.ContextMenu = Me.cmDataGrid
        CType(Me, System.ComponentModel.ISupportInitialize).EndInit()
 
        miColumns = New MenuItem
 
        cmDataGrid.MenuItems.AddRange(New MenuItem() {miColumns})
 
        miColumns.DefaultItem = True
        miColumns.Index = 0
        miColumns.Text = "Columns"
   End If

Open in new window

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:
This works, thank you very much for your help
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.