Solved

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

Posted on 2013-11-28
3
913 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Assisted Solution

by:Valliappan AN
Valliappan AN earned 250 total points
ID: 39683626
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 63

Accepted Solution

by:
Fernando Soto earned 250 total points
ID: 39683824
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
ID: 39683917
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

729 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