Link to home
Start Free TrialLog in
Avatar of tatamaruri
tatamaruri

asked on

error UserControl when run app????? (vs.NET2005)

I created a UserControl in Windows form. I built the control successfully. but when I added that control to an app then I got this error:

-----------
One or more errors encountered while loading the designer. The errors are listed below. Some errors can be fixed by rebuilding your project, while others may require code changes.

Object reference not set to an instance of an object.
Hide    

at System.ComponentModel.ReflectPropertyDescriptor.SetValue(Object component, Object value)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeAssignStatement(IDesignerSerializationManager manager, CodeAssignStatement statement)
at System.ComponentModel.Design.Serialization.CodeDomSerializerBase.DeserializeStatement(IDesignerSerializationManager manager, CodeStatement statement)
--------------

I found that if without this code in usercontrol my app had no problem:

---------------
 <Category("Get Data"), DefaultValue("")> Public Property GetTable() As String
        Get
            Return Me._tableName
        End Get
        Set(ByVal value As String)
            Dim a As String = ""
            For Each name As DataTable In Me._data.Tables
                If name.TableName.ToUpper() = value.ToUpper() Then
                    Me._tableName = value
                    Exit Property
                End If
            Next
            Throw New ArgumentException("there is no this table")
        End Set
    End Property
-----------------

thanks in advance
Avatar of YoungBonzi
YoungBonzi
Flag of United States of America image

There's an area that you're not supposed to modify if you want to use the designer...it should be pre-commented.

If you undo what you changed in there, the designer should work again.
That area of code is from:
#pragma region Windows Form Designer generated code
...
to
...
#pragma endregion

If you could post the code you have in between there, perhaps we can see what the problem is. =)
I'm sorry I thought you were using C++...never mind what I wrote.
Avatar of Daniel Van Der Werken
What happens if you don't use the attribute <Category("Get Data"), DefaultValue("")> ?

Avatar of tatamaruri
tatamaruri

ASKER

still error :(
Ah... I fixed it.
Because I had a condition "if" to get GetTable property. So when I had value in form but did not have in control class make it conflict.
Now I make some codes to remove that value in form and the error disappear.
Anyway... thanks all of you
I had another solution. I fix previous code to:

    <Category("Get Data"), DefaultValue("")> Public Property GetTable() As String
        Get
            Return Me._tableName
        End Get
        Set(ByVal value As String)
            If _data IsNot Nothing Then
                For Each name As DataTable In Me._data.Tables
                    If name.TableName.ToUpper() = value.ToUpper() Then
                        Me._tableName = value
                        Exit Property
                    End If
                Next
                Throw New ArgumentException("there is no this table")
            End If
        End Set
    End Property
I think the error was because the data list had nothing in it and the code was trying to use a value from it.
ASKER CERTIFIED SOLUTION
Avatar of DarthMod
DarthMod
Flag of United States of America 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