Results 1 to 3 of 3

Thread: Calling form controls from Module

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Question Calling form controls from Module

    Hi All,

    I have a Sub Routine in a module to iterate controls on a form. I get an error about an instance of the object not created.

    I have declared the object and set it to the form (ModelsBox = Me). I have done this between two forms previously. Is there something fundamental that I am missing. Is this where the "Friend Shared" comes into play?

    Code:
    Namespace Models_DialogBox
    
        Public Class Mod_DlgBox
            <CommandMethod("EM")> _
            Public Sub EM()
                LoadForm()
            End Sub
        End Class
    
    End Namespace
    
    
    Friend Module Module1
        Friend ModelsBox As Form
    
        Public Sub LoadForm()
            Dim Models As Form = New FrmModBox
            Models.Show()
        End Sub
    
        Public Sub UpdateStatus()
            For Each oControl As Control In ModelsBox.Controls("TableLayoutPanel1").Controls ' This is the error
                ' my code
            Next
        End Sub
    
    End Module
    
    Friend Class FrmModBox
        Private Sub FrmModBox_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            ModelsBox = Me
        End Sub
    
    End Class
    Thanks in advance,

    Brent

  2. #2

    Re: Calling form controls from Module

    Why are you creating controls from a module, and not making them in the designer?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2008
    Location
    Perth, Australia
    Posts
    101

    Re: Calling form controls from Module

    I already have the controls on the form.

    I have 9 listview boxes in a table panel (3 x 3). What I want to do is look in the Table Panel and get a specific listvew. I can get it to work if I have
    Code:
    Public Sub UpdateStatus()
            For Each oControl As Control In ModelsBox.Controls("TableLayoutPanel1").Controls ' This is the error
                ' my code
            Next
        End Sub
    in the form. My problem is that when an event is triggered in the ListViews, it runs a separate Subroutine, in which it calls the UpdateStatus.

    I don't know if that has made it any clearer.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width