Solved

How to access the property of a child usercontrol form in c# or vb.net

Posted on 2013-11-28
3
885 Views
Last Modified: 2013-11-28
Hello,

I have a windows form with a panel wich include a usercontrol form.
Now i have to run some code on the main (parent) form, that checks the value of a property on the child form(usercontrol in panel).

I have created a public readonly property on the usercontrol, but when i try to read this i can't get the value.

I also get the error message "Conversion from string "" to type 'Integer' is not valid." on line  If uc.rl1 = True.

Property on usercontrol:
 Public ReadOnly Property rl1() As Boolean
        Get
            Dim r As Integer
            r = CInt(Me.txtRowIndex.Text)
            If r > -1 Then
                Return DGTimeTable.Item(4, r).Value
            Else
                Return False
            End If
        End Get
      End Property

Open in new window


Code on mainform that should read this property:
 Dim buffer As Byte()
            ReDim buffer(2)
            Dim uc As ucTestform = New ucTestform
            uc = Me.ucPanel.Controls.Find("ucTestform", False)(0)
          
            If uc.rl1 = True Then buffer(0) = buffer(0) Or 128 Else buffer(0) = buffer(0) And 127
         

Open in new window


Thanks in advance.

Edward
0
Comment
Question by:nijmedw
3 Comments
 
LVL 9

Assisted Solution

by:Valliappan AN
Valliappan AN earned 250 total points
Comment Utility
The error, could be from here:

r = CInt(Me.txtRowIndex.Text)


You may check if its a valid integer, before conversion.  You may try:

Convert.ToInt32(Me.txtRowIndex.Text) or, better, option would be:

Int32.TryParse(Me.txtRowIndex.Text)

 Hope  that helps.
0
 
LVL 62

Accepted Solution

by:
Fernando Soto earned 250 total points
Comment Utility
Hi Edward;

I suspect that the value being returned by DGTimeTable.Item(4, r).Value in the property rl1 is a string. What are the possible values that it can return? If the values are string like "True", "true", "False", or "false" then change that line to this.

Return Boolean.Parse(DGTimeTable.Item(4, r).Value)

If other values are being returned please post them here.
0
 

Author Closing Comment

by:nijmedw
Comment Utility
I was stupid. The rowindex was empty, so it couldn't convert it to an integer. And the combinatin with boolean.parcse etc...  did the trick.

Thanks a lot both of you.

Regards,

Edward
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now