Solved

public event usage

Posted on 2009-05-06
3
160 Views
Last Modified: 2013-11-07
I am having a little trouble with this as I have never used a public event.  I have one VB.net user control that acts like a form.  There is a button on this user control that calls another user control which is also displayed like a form.  this is not a modal.  We have an interface in  place that handles these usercontrols and puts them into tabs.  basically what I think I need to do is raise a public event that will in turn call a method on the calling user control when the called user control is saved.  Any ideas?
0
Comment
Question by:oak29
  • 2
3 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 24318731
How is the first UserControl "calling" the second one?  Does it have a reference to it?...or is it raising an event that the Form catches and then "passes" on to the second?  If one has a reference to the other already then you should be able to subscribe to a custom event that the second usercontrol raises...
0
 

Author Comment

by:oak29
ID: 24318865
this is essentially as far as I have gotten.  This is not working


Calling usercontrol

I have this in the load of the calling form

Dim _CalledUserControl As CalledUserControl = New CalledUserControl ()
            AddCalledUserControl handler(_NoticeOfLoss)  --> Adding my event

These are two sub procedures in the calling form

Public Sub AddCalledUserControl (ByVal oCalledUserControl  As CalledUserControl )

        AddHandler oCalledUserControl.Event, AddressOf CallingUserControl_LoadMethod

    End Sub

    Private Sub CallingUserControl_LoadMethod()
        LoadMethod()  ---Method I am trying to call
    End Sub


I have this declared as Global in my Called user Control
Public Event Event()

I have this when I click my save changes button
RaiseEvent Event()
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 24414223
Ok...not sure I follow everything but here is an example of UserControl1 creating an instance of UserControl2 and subscribing to one of its custom events:

Public Class UserControl1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim uc2 As New UserControl2
        AddHandler uc2.MyEvent, AddressOf uc2_MyEvent
        uc2.Location = New Point(Button1.Location.X, Button1.Location.Y + Button1.Height)
        Me.Controls.Add(uc2)
    End Sub

    Private Sub uc2_MyEvent()
        MessageBox.Show("MyEvent() received from uc2!")
    End Sub

End Class

Public Class UserControl2

    Public Event MyEvent()

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        RaiseEvent MyEvent()
    End Sub

End Class

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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 is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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