Link to home
Start Free TrialLog in
Avatar of ACAE
ACAE

asked on

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
Avatar of indianguru2
indianguru2
Flag of India image

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

ASKER

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
What have you added in New()
Avatar of ACAE

ASKER


    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
ASKER CERTIFIED SOLUTION
Avatar of indianguru2
indianguru2
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ACAE

ASKER

This works, thank you very much for your help