?
Solved

working with controls on multiple forms

Posted on 2008-01-30
3
Medium Priority
?
161 Views
Last Modified: 2010-04-23
I have the following routine that searces for a control and removes it from a tabpage.
However, I also have need to pass the form, but if I use something like frm.tab, I obviously get an error that tab's not a member of frm.

So, the first part of my question is how can I accomplish this.
The latter part, which is probably going to be answered the same way is - how can I move this to a module?  I have a custom class where I need access to the same sub - I'd rather have only one instance instead of dropping a second in the other class...
Private Sub DestroyControl(ByVal strName As String, ByVal tab As TabPage)
        Dim ctl() As Control = tab.Controls.Find(strName, True)
        If ctl.Length > 0 Then
            ctl(0).Visible = False
            tab.Controls.Remove(ctl(0))
        End If
        ctl = Nothing
    End Sub

Open in new window

0
Comment
Question by:sirbounty
  • 2
3 Comments
 
LVL 34

Accepted Solution

by:
Sancler earned 2000 total points
ID: 20782665
You need to add another layer in to the find control sequence.  Following your present approach, you could have a sub something like this

    Public Sub DestroyControl(ByVal frm As Form, ByVal strName As String, ByVal tabpagename As String)
        Dim tab As TabPage
        Dim thetab() As Control = frm.Controls.Find(tabpagename, True)
        If thetab.Length > 0 Then
            tab = thetab(0)
            Dim ctl() As Control = tab.Controls.Find(strName, True)
            If ctl.Length > 0 Then
                ctl(0).Visible = False
                tab.Controls.Remove(ctl(0))
            End If
            ctl = Nothing
        End If
        tab = Nothing
    End Sub

I've made that Public, rather than private, so even if the code is on form1 you could call it from any other form.  But - picking up on your module question - you could put it in a module or class.  I've added a Form argument.  And I've changed the tab argument to a String - giving the name of the tabpage.  But, as I say, I've basically just followed your approach and added an "extra layer".  For real life purposes you'll probably want to tart it up or streamline it.  But it illustrates the approach.

Roger
0
 
LVL 67

Author Comment

by:sirbounty
ID: 20783540
Hmm - tart it up...interesting suggestion...heh heh.
Thanx Roger - I was hoping you would come to my aid once again.  I'll try this out first thing in the morning. :^)
0
 
LVL 67

Author Comment

by:sirbounty
ID: 20799892
Perfect - thanx as always! :^)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Watch the video to learn how one can deal with PST file corruption issue with an outstanding Kernel for Outlook PST Repair Tool easily. Using this tool, non-technical users can swiftly perform the repair process to restore their essential data witho…
Suggested Courses

601 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