Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2013-11-28
3
Medium Priority
?
955 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 750 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 64

Accepted Solution

by:
Fernando Soto earned 750 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview
Suggested Courses

877 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