Sharing Events?

I have attached a screenshot that shows a TabControl along with several groupbox controls. Each groupbox is comprised of multiple controls. These controls make up a UserControl. Each of the tabpages, excluding the "Equipment Selection" tab are laid out exactly the same. Each control is named according to the tabpage it resides on; example - usrChannelAngleLoadTest, usrChannelAngleRepeatabilityTest, usrChannelAngleCreepTest, etc.

Each of these controls have public events defined in the UC code-behind. Here is an example of these events.

    Private Sub usrLoadSettingsCreep_GetUnitType() Handles usrLoadSettingsCreep.GetUnitType
        Try
            EH.ErrorMessage = String.Empty

            If usrLoadSettingsCreep.cmbLoadUnitType.SelectedIndex <> -1 Then
                If gblnLoadUnitTypeSelectedCreep Then
                    gblnLoadUnitTypeSelectedCreep = False

                    RemoveHandler usrLoadSettingsCreep.cmbLoadUnit.SelectedIndexChanged, AddressOf usrLoadSettingsCreep.cmbLoadUnit_SelectedIndexChanged
                    LoadCombo_LoadUnits(usrLoadSettingsCreep.cmbLoadUnitType.SelectedValue, usrLoadSettingsCreep.cmbLoadUnit)
                    AddHandler usrLoadSettingsCreep.cmbLoadUnit.SelectedIndexChanged, AddressOf usrLoadSettingsCreep.cmbLoadUnit_SelectedIndexChanged
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/usrLoadSettingsCreep_GetUnitType() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub
    '
    '
    '
    Private Sub usrLoadSettingsRepeat_GetUnitType() Handles usrLoadSettingsRepeat.GetUnitType
        Try
            EH.ErrorMessage = String.Empty

            If usrLoadSettingsRepeat.cmbLoadUnitType.SelectedIndex <> -1 Then
                If gblnLoadUnitTypeSelectedRepeat Then
                    gblnLoadUnitTypeSelectedRepeat = False

                    RemoveHandler usrLoadSettingsRepeat.cmbLoadUnit.SelectedIndexChanged, AddressOf usrLoadSettingsRepeat.cmbLoadUnit_SelectedIndexChanged
                    LoadCombo_LoadUnits(usrLoadSettingsRepeat.cmbLoadUnitType.SelectedValue, usrLoadSettingsRepeat.cmbLoadUnit)
                    AddHandler usrLoadSettingsRepeat.cmbLoadUnit.SelectedIndexChanged, AddressOf usrLoadSettingsRepeat.cmbLoadUnit_SelectedIndexChanged
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/usrLoadSettingsRepeat_GetUnitType() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub
    '
    '
    '
    Private Sub usrLoadSettingsLoad_GetUnitType() Handles usrLoadSettingsLoad.GetUnitType
        Try
            EH.ErrorMessage = String.Empty

            If usrLoadSettingsLoad.cmbLoadUnitType.SelectedIndex <> -1 Then
                If gblnLoadUnitTypeSelectedLoad Then
                    gblnLoadUnitTypeSelectedLoad = False

                    RemoveHandler usrLoadSettingsLoad.cmbLoadUnit.SelectedIndexChanged, AddressOf usrLoadSettingsLoad.cmbLoadUnit_SelectedIndexChanged
                    LoadCombo_LoadUnits(usrLoadSettingsLoad.cmbLoadUnitType.SelectedValue, usrLoadSettingsLoad.cmbLoadUnit)
                    AddHandler usrLoadSettingsLoad.cmbLoadUnit.SelectedIndexChanged, AddressOf usrLoadSettingsLoad.cmbLoadUnit_SelectedIndexChanged
                End If
            End If

        Catch ex As Exception

        End Try
    End Sub

Open in new window


My question is this!

Is there any way of consolidating these three events into one event where I can just pass in the UC depending on which one is being called at the time? Basically having all three events share one event!

Thanks
Screenshot.jpg
BlakeMcKennaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Change the Handles on one of the events to this

Handles usrLoadSettingsCreep.GetUnitType, usrLoadSettingsRepeat.GetUnitType, ...

Then delete the other events. Inside the event that remains you need to find out which event triggered the event.
0
BlakeMcKennaAuthor Commented:
Fernando,

Using your idea, how can pass a string variable into that event that is specific to the "Load", "Creep" or "Repeat"? What needs to be modified in all the UC's?

Thanks!
0
Fernando SotoRetiredCommented:
Hi BlakeMcKenna;

Not sure if these are regular event handlers but that are more likely home grown because they have no parameters. So if that is the case please have a look at this web page Handling and Raising Events. When raising the event you apply two parameters the Me object and a EventArgs. This way when the event is handled by your code you get a sender and a event. Then you can cast the sender to a control and you will be able to tell who raised the event.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BlakeMcKennaAuthor Commented:
Thanks Fernando...that helped!
0
Fernando SotoRetiredCommented:
Not a problem BlakeMcKenna, glad I was able to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.