We help IT Professionals succeed at work.
Get Started

Sharing Events?

BlakeMcKenna
BlakeMcKenna asked
on
93 Views
Last Modified: 2015-04-24
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
Comment
Watch Question
Retired
CERTIFIED EXPERT
Distinguished Expert 2017
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE