UserControl not working correctly?

I have a usercontrol that is dynamically placed on 3 dynamically created tabPages. The UC itself is basically two DataGridViews that allow a user to make selections. Each UC can contain different selections, at least that's the way its suppose to work. However, when I make a selection on one tab, that selection seems to be reflected in each instance of the UC. See the screenshot for an understanding.

I only made one selection and that was on the first tab (View this screenshot first). Below is the entire code for the UserControl.

Public Class userChannelEquipment

    Private blnSelected As Boolean = False
    Private blnIsLoaded As Boolean = False

    Private f As frmCalibration_3

    Public Sub New()
        Try
            InitializeComponent()

            blnIsLoaded = True

        Catch ex As Exception
            EH.ErrorMessage = "userChannelEquipment/New() - " & ex.Message
        End Try
    End Sub

    Private Sub userChannelEquipment_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            EH.ErrorMessage = String.Empty

            ApplyUserSettings(gUser_ID, f)

        Catch ex As Exception
            EH.ErrorMessage = "userChannelEquipment/userChannelEquipment_Load() - " & ex.Message
        End Try
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub dgvSTEquipmentAvail_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvSTEquipmentAvail.CellMouseUp
        Try
            EH.ErrorMessage = String.Empty

            If e.RowIndex > -1 And e.ColumnIndex >= 0 Then
                If (blnIsLoaded) AndAlso Not (IsNothing(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)) Then
                    Dim cboSelected As DataGridViewCheckBoxCell = CType(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(0), DataGridViewCheckBoxCell)

                    If e.ColumnIndex <> 0 Then
                        GoTo ProcessMessage
                    End If

                    If CBool(cboSelected.Value) <> False Then
                        For Each row As DataGridViewRow In dgvSTSelectedEquipment.Rows
                            If CStr(row.Cells(0).Value) = CStr(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(1).Value) Then
                                EH.ErrorMessage = "Equipment already selected!" & "~I"

                                If CBool(cboSelected.Value) = True Then
                                    cboSelected.Value = False
                                    dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = CBool(cboSelected.Value)
                                End If

                                blnSelected = True
                                Exit For
                            End If
                        Next
                    Else
                        f.RemoveSelectedEquipment(CStr(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(1).Value))
                        If EH.ErrorMessage > String.Empty Then
                            GoTo ProcessMessage
                        End If
                    End If

                    If blnSelected Then
                        blnSelected = False
                        GoTo ProcessMessage
                    End If

                    If CBool(cboSelected.Value) Then
                        Dim row As DataGridViewRow = dgvSTEquipmentAvail.CurrentRow
                        Dim sRow As DataRow = dbConnectedEquip.NewRow

                        sRow("equipment_ID") = row.Cells(1).Value
                        sRow("equipmentType") = row.Cells(2).Value
                        sRow("serialNO") = row.Cells(4).Value
                        sRow("equipmentName") = row.Cells(5).Value
                        sRow("modelNO") = row.Cells(15).Value
                        sRow("stationName") = row.Cells(7).Value
                        sRow("accredited") = If(IsDBNull(row.Cells(8).Value), CBool(0), CBool(row.Cells(8).Value))

                        dbConnectedEquip.Rows.Add(sRow)

                        dgvSTSelectedEquipment.DataSource = dbConnectedEquip
                    Else
                        dgvSTEquipmentAvail.Rows(e.RowIndex).DefaultCellStyle.Font = New Font(dgvSTEquipmentAvail.Font.Name, dgvSTEquipmentAvail.Font.Size, FontStyle.Regular)
                    End If
                End If
            End If

ProcessMessage:

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

    Private Sub dgvSTEquipmentAvail_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgvSTEquipmentAvail.CurrentCellDirtyStateChanged
        Try
            EH.ErrorMessage = String.Empty

            If Not (IsNothing(dgvSTEquipmentAvail.IsCurrentCellDirty)) AndAlso dgvSTEquipmentAvail.IsCurrentCellDirty Then
                dgvSTEquipmentAvail.CommitEdit(DataGridViewDataErrorContexts.Commit)
            End If

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

Open in new window

Selected-Equipment-ID-184.JPG
Different-Tab-Same-Selection.JPG
Different-Tab-Same-Selection-2.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.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
When you create the 3 instances of "userChannelEquipment", are you wiring up any events with "AddHandler"?
BlakeMcKennaAuthor Commented:
Yes...I've created one Event and that event loads the datagridview with data. Below is the Event.

The follow Sub creates to sets of UserControls. They both place these UC's on dynamically created TabPages.

    Private Sub BuildChannelControlTabs()

        Dim x As Integer = 0

        Try
            EH.ErrorMessage = String.Empty

            If tabTests.TabPages.Contains(tabChannels) Then
                For Each itm In arrChannels
                    Dim tab As New TabPage
                    Dim uC1 As New userChannelSettings

                    uC1.Name = "ucChannel" & x + 1
                    'uC1.mlChannelName.Text = itm
                    tab.Controls.Add(uC1)
                    uC1.ForeColor = tab.ForeColor

                    AddHandler uC1.Load, AddressOf ucChannel_Load

                    tab.Tag = itm
                    tab.Text = "Channel: " & itm.ToString
                    tab.Name = "tChannel" & x + 1
                    tabChannelList.Controls.Add(tab)

                    x += 1
                Next
            Else
                EH.ErrorMessage = "Invalid Control Creation!" & "~E"
                GoTo ProcessMessage
            End If

            x = 0

            If tabTests.TabPages.Contains(tabEquipmentByChannel) Then
                For Each itm In arrChannels
                    Dim tab As New TabPage
                    Dim uC2 As New userChannelEquipment()

                    uC2.Name = "ucEquipment" & x + 1
                    uC2.Location = New Point(5, 5)
                    tab.Controls.Add(uC2)
                    uC2.ForeColor = tab.ForeColor

                    AddHandler uC2.Load, AddressOf ucEquipment_Load

                    tab.Tag = itm
                    tab.Text = "Channel: " & itm.ToString
                    tab.Name = "tEquipment" & x + 1
                    tabChannelEquipment.Controls.Add(tab)

                    x += 1
                Next
            Else
                EH.ErrorMessage = "Invalid Control Creation!" & "~E"
            End If

ProcessMessage:

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

[code]
    Private Sub ucEquipment_Load(sender As Object, e As EventArgs)

        Dim uc As userChannelEquipment = DirectCast(sender, userChannelEquipment)

        Try
            EH.ErrorMessage = String.Empty

            InitializeErrorClass(EH)
            BL.LoadGrid_Equipment(iEquipmentType_ID, iCalibration_ID, EH)

            If EH.ErrorMessage = String.Empty Then
                If EH.DataTable.Rows.Count > 0 Then
                    bsEquipmentGrid.DataSource = EH.DataTable
                    uc.dgvSTEquipmentAvail.DataSource = bsEquipmentGrid
                    uc.dgvSTEquipmentAvail.Columns(10).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(11).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(12).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(13).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(14).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(15).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(16).Visible = False
                    uc.dgvSTEquipmentAvail.AutoGenerateColumns = True
                    uc.dgvSTEquipmentAvail.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
                    uc.dgvSTEquipmentAvail.ClearSelection()
                Else
                    EH.ErrorMessage = "You have no Equipment defined...you cannot proceed!" & "~I"
                End If
            End If

            LoadConnectedDevices(uc.dgvSTSelectedEquipment, uc.dgvSTEquipmentAvail)

ProcessMessage:

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

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

BlakeMcKennaAuthor Commented:
Sorry...I forgot a closing Tag.

    Private Sub BuildChannelControlTabs()
        'Debug.Print("BuildChannelControlTabs")

        Dim x As Integer = 0

        Try
            EH.ErrorMessage = String.Empty

            If tabTests.TabPages.Contains(tabChannels) Then
                For Each itm In arrChannels
                    Dim tab As New TabPage
                    Dim uC1 As New userChannelSettings

                    uC1.Name = "ucChannel" & x + 1
                    'uC1.mlChannelName.Text = itm
                    tab.Controls.Add(uC1)
                    uC1.ForeColor = tab.ForeColor

                    AddHandler uC1.Load, AddressOf ucChannel_Load

                    tab.Tag = itm
                    tab.Text = "Channel: " & itm.ToString
                    tab.Name = "tChannel" & x + 1
                    tabChannelList.Controls.Add(tab)

                    x += 1
                Next
            Else
                EH.ErrorMessage = "Invalid Control Creation!" & "~E"
                GoTo ProcessMessage
            End If

            x = 0

            If tabTests.TabPages.Contains(tabEquipmentByChannel) Then
                For Each itm In arrChannels
                    Dim tab As New TabPage
                    Dim uC2 As New userChannelEquipment()

                    uC2.Name = "ucEquipment" & x + 1
                    uC2.Location = New Point(5, 5)
                    tab.Controls.Add(uC2)
                    uC2.ForeColor = tab.ForeColor

                    AddHandler uC2.Load, AddressOf ucEquipment_Load

                    tab.Tag = itm
                    tab.Text = "Channel: " & itm.ToString
                    tab.Name = "tEquipment" & x + 1
                    tabChannelEquipment.Controls.Add(tab)

                    x += 1
                Next
            Else
                EH.ErrorMessage = "Invalid Control Creation!" & "~E"
            End If

ProcessMessage:

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

Open in new window


    Private Sub ucEquipment_Load(sender As Object, e As EventArgs)
        'Debug.Print("ucEquipment_Load")

        Dim uc As userChannelEquipment = DirectCast(sender, userChannelEquipment)

        Try
            EH.ErrorMessage = String.Empty

            InitializeErrorClass(EH)
            BL.LoadGrid_Equipment(iEquipmentType_ID, iCalibration_ID, EH)

            If EH.ErrorMessage = String.Empty Then
                If EH.DataTable.Rows.Count > 0 Then
                    bsEquipmentGrid.DataSource = EH.DataTable
                    uc.dgvSTEquipmentAvail.DataSource = bsEquipmentGrid
                    uc.dgvSTEquipmentAvail.Columns(10).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(11).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(12).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(13).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(14).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(15).Visible = False
                    uc.dgvSTEquipmentAvail.Columns(16).Visible = False
                    uc.dgvSTEquipmentAvail.AutoGenerateColumns = True
                    uc.dgvSTEquipmentAvail.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
                    uc.dgvSTEquipmentAvail.ClearSelection()
                Else
                    EH.ErrorMessage = "You have no Equipment defined...you cannot proceed!" & "~I"
                End If
            End If

            LoadConnectedDevices(uc.dgvSTSelectedEquipment, uc.dgvSTEquipmentAvail)

ProcessMessage:

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

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
The problem is here:
bsEquipmentGrid.DataSource = EH.DataTable

Open in new window


Give each grid its own view:
bsEquipmentGrid.DataSource = New DataView(EH.DataTable)

Open in new window


Now they should be able to have different selected rows at the same time.
BlakeMcKennaAuthor Commented:
Unfortunately that did not work.

Whatever selection I make on a UC for any tab, that's what appears on the other tabs' UC as well.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You'd need to do the same thing for the bottom DataGridView...

Change:

    dgvSTSelectedEquipment.DataSource = dbConnectedEquip

To:

    dgvSTSelectedEquipment.DataSource = New DataView(dbConnectedEquip)

Look for all places where you're setting the DataSource.
BlakeMcKennaAuthor Commented:
Still not working. It's acting kinda weird anyway. It appears to be loading the DGV when it shouldn't be. I need to figure out why that's happening. That might shed some light then.
BlakeMcKennaAuthor Commented:
Mike,

I think what may be happening is that the created TabPage has no Event to link each separate UC. In other words, each click of the tab references the same UC. I'm not sure how to word that but I think that's what's happening. In the section where I create the AddHandler "ucEquipment_Load"...I'm wondering if I need to add a new Event in the "ucEquipment_Load" event that manages which TabPage is selected?
BlakeMcKennaAuthor Commented:
I really have a difficult time in understanding how to reference dynamic controls within a Form Module.
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
You can't have the same control in more than one location.   Adding a control to another container will remove it from the current container.

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:
Ok,

What I'm saying is that when I check a specific row in the dgv on a specific tabpage, and then click on another tabpage...that same row that I just checked in previous tabpage is checked in the dgv of the current tabpage.
BlakeMcKennaAuthor Commented:
OK,

I've taken a different route only because I cannot get this functionality working. I have since removed any dynamic Tab creation. Instead, I have added 12 TabPages to the TabControl via the designer. However, I still dynamically place a UC on each TabPage.

When the program first runs, I remove all the TabPages from the TabControl. I then add them back in based on certain logic (checking a checkbox). That portion works fine. The problem that I'm now having is when I go to remove them and/or add them back in. That portion isn't working.

I add/remove a TabPage based on checking/unchecking a checkbox.

Below is the logic used to add/remove the TabPages. By the way, the TabPages are names in such a fashion:

tChannel1...tChannel12

    Private Sub cboChannels_Click(sender As Object, e As EventArgs) Handles cboChannels.Click

        Dim tabP As New TabPage
        Dim cbo As CheckBox = DirectCast(sender, CheckBox)            
        Dim strTabName As String = String.Empty

        Try
            EH.ErrorMessage = String.Empty

           'The "Tag" property contains numeric values: 1 - 12

            If cbo.Checked Then
                strTabName = "tChannel" & cbo.Tag                 
                tabP.Name = strTabName

                If Not tabChannelList.TabPages.ContainsKey(strTabName) Then
                    tabChannelList.TabPages.Add(tabP)
                End If
            Else
                strTabName = "tChannel" & cbo.Tag
                tabP.Name = strTabName

                If tabChannelList.TabPages.ContainsKey(strTabName) Then
                    tabChannelList.TabPages.Remove(tabP)
                End If
            End If

ProcessMessage:

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

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window



Here is the code that creates the dynamic UC's as well as adds the TabPage to the TabControl.

    Private Sub BuildChannelControlTabs()
        Try
            EH.ErrorMessage = String.Empty

            If tabTests.TabPages.Contains(tabChannels) Then
                For x As Integer = 0 To stcChannels.Length - 1
                    Dim tab As New TabPage
                    Dim uC1 As New userChannelSettings

                    uC1.Name = "ucChannel" & x + 1
                    uC1.Tag = stcChannels(x).channel_ID
                    tab.Controls.Add(uC1)
                    uC1.ForeColor = tab.ForeColor

                    AddHandler uC1.Load, AddressOf ucChannel_Load

                    tab.Name = "tChannel" & x + 1
                    tab.Tag = stcChannels(x).channel_ID
                    tab.Text = "Channel: " & stcChannels(x).channel

                    If Not tabChannelList.TabPages.Contains(tab) Then
                        tabChannelList.TabPages.Add(tab)
                    End If
                Next
            Else
                EH.ErrorMessage = "Invalid Control Creation!" & "~E"
                GoTo ProcessMessage
            End If

ProcessMessage:

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

Open in new window

BlakeMcKennaAuthor Commented:
I still can't get this working!!
BlakeMcKennaAuthor Commented:
I have spent 4 full days on trying to figure this out and I'm just not seeing the problem. I have included the entire class for the UserControl along with a Word document with images and explanations. I have also included and identified Form level code that is referenced in some way by the UC.

userChannelEquipment.vb

Public Class userChannelEquipment

    Private blnSelected As Boolean = False
    Private blnIsLoaded As Boolean = False

    Public Event EquipmentCellMouseClick(sender As Object, e As DataGridViewCellMouseEventArgs)
    '
    '
    '
    Private Sub userChannelEquipment_Load(sender As Object, e As EventArgs) Handles Me.Load
        Try
            EH.ErrorMessage = String.Empty

            ApplyUserSettings(gUser_ID, frmCalibration_3)
            If EH.ErrorMessage > String.Empty Then
                GoTo ProcessMessage
            End If

            blnIsLoaded = True

ProcessMessage:

        Catch ex As Exception
            EH.ErrorMessage = "userChannelEquipment/userChannelEquipment_Load() - " & ex.Message
        End Try

        EH.ProcessMessages(frmCalibration_3, frmCalibration_3.sbr, EH.ErrorMessage)
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub dgvSTEquipmentAvail_CellMouseUp(sender As Object, e As DataGridViewCellMouseEventArgs) Handles dgvSTEquipmentAvail.CellMouseUp
        Try
            EH.ErrorMessage = String.Empty

            If e.RowIndex > -1 And e.ColumnIndex >= 0 Then
                If (blnIsLoaded) AndAlso Not (IsNothing(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(e.ColumnIndex).Value)) Then
                    Dim cboSelected As DataGridViewCheckBoxCell = CType(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(0), DataGridViewCheckBoxCell)

                    If e.ColumnIndex <> 0 Then
                        GoTo ProcessMessage
                    End If

                    If CBool(cboSelected.Value) <> False Then
                        For Each row As DataGridViewRow In dgvSTSelectedEquipment.Rows
                            If CStr(row.Cells(0).Value) = CStr(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(1).Value) Then
                                EH.ErrorMessage = "Equipment already selected!" & "~I"

                                If CBool(cboSelected.Value) = True Then
                                    cboSelected.Value = False
                                    dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(e.ColumnIndex).Value = CBool(cboSelected.Value)
                                End If

                                blnSelected = True
                                Exit For
                            End If
                        Next
                    Else
                        frmCalibration_3.RemoveSelectedEquipment(CStr(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(1).Value), CInt(dgvSTEquipmentAvail.Rows(e.RowIndex).Cells(1).Value), dgvSTEquipmentAvail)
                        If EH.ErrorMessage > String.Empty Then
                            GoTo ProcessMessage
                        End If
                    End If

                    If blnSelected Then
                        blnSelected = False
                        GoTo ProcessMessage
                    End If

                    If CBool(cboSelected.Value) Then
                        Dim row As DataGridViewRow = dgvSTEquipmentAvail.CurrentRow
                        Dim sRow As DataRow = dbConnectedEquip.NewRow

                        sRow("equipment_ID") = row.Cells(1).Value
                        sRow("equipmentType") = row.Cells(2).Value
                        sRow("serialNO") = row.Cells(4).Value
                        sRow("equipmentName") = row.Cells(5).Value
                        sRow("modelNO") = row.Cells(15).Value
                        sRow("stationName") = row.Cells(7).Value
                        sRow("accredited") = If(IsDBNull(row.Cells(8).Value), CBool(0), CBool(row.Cells(8).Value))
                        sRow("channel_ID") = If(IsDBNull(row.Cells(17).Value), 0, row.Cells(17).Value)

                        dbConnectedEquip.Rows.Add(sRow)
                        dgvSTSelectedEquipment.DataSource = New DataView(dbConnectedEquip)
                    Else
                        dgvSTEquipmentAvail.Rows(e.RowIndex).DefaultCellStyle.Font = New Font(dgvSTEquipmentAvail.Font.Name, dgvSTEquipmentAvail.Font.Size, FontStyle.Regular)
                    End If
                End If
            End If

ProcessMessage:

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

        EH.ProcessMessages(frmCalibration_3, frmCalibration_3.sbr, EH.ErrorMessage)
    End Sub

    Private Sub dgvSTEquipmentAvail_CurrentCellDirtyStateChanged(sender As Object, e As EventArgs) Handles dgvSTEquipmentAvail.CurrentCellDirtyStateChanged
        Try
            EH.ErrorMessage = String.Empty

            If Not (IsNothing(dgvSTEquipmentAvail.IsCurrentCellDirty)) AndAlso dgvSTEquipmentAvail.IsCurrentCellDirty Then
                dgvSTEquipmentAvail.CommitEdit(DataGridViewDataErrorContexts.Commit)
            End If

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

        EH.ProcessMessages(frmCalibration_3, frmCalibration_3.sbr, EH.ErrorMessage)
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub cmbEquipmentType_KeyDown(sender As Object, e As KeyEventArgs) Handles cmbEquipmentType.KeyDown
        e.SuppressKeyPress = True
    End Sub

    Private Sub cmbEquipmentType_SelectionChangeCommitted(sender As Object, e As EventArgs) Handles cmbEquipmentType.SelectionChangeCommitted
        Try
            EH.ErrorMessage = String.Empty

            If cmbEquipmentType.SelectedIndex > -1 Then
                'frmCalibration_3.LoadGrid_Equipment(cmbEquipmentType.SelectedValue, dgvSTEquipmentAvail, dgvSTEquipmentAvail.Rows(0).Cells(17).Value)
                frmCalibration_3.LoadGrid_Equipment(cmbEquipmentType.SelectedValue, Me, dgvSTEquipmentAvail.Rows(0).Cells(17).Value)
                If EH.ErrorMessage = String.Empty Then
                    frmCalibration_3.ReloadSelectedEquipment(dgvSTEquipmentAvail)
                End If
            End If

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

        EH.ProcessMessages(frmCalibration_3, frmCalibration_3.sbr, EH.ErrorMessage)
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub btnClearSelections_Click(sender As Object, e As EventArgs) Handles btnClearSelections.Click
        Try
            EH.ErrorMessage = String.Empty

            dbConnectedEquip.Rows.Clear()

            For Each row As DataGridViewRow In dgvSTEquipmentAvail.Rows
                Dim cb As DataGridViewCheckBoxCell = CType(row.Cells(0), DataGridViewCheckBoxCell)

                cb.Value = False

                If Not IsDBNull(row.Cells(12).Value) And row.Cells(12).Value <> 0 Then
                    If gWorkStation_ID = CInt(row.Cells(12).Value) Then
                        cb.Value = True

                        Dim sRow As DataRow = dbConnectedEquip.NewRow

                        sRow("equipment_ID") = row.Cells(1).Value
                        sRow("equipmentType") = row.Cells(2).Value
                        sRow("serialNO") = row.Cells(4).Value
                        sRow("equipmentName") = row.Cells(5).Value
                        sRow("stationName") = row.Cells(7).Value
                        sRow("accredited") = If(IsDBNull(row.Cells(8).Value), CBool(0), CBool(row.Cells(8).Value))
                        sRow("channel_ID") = Me.Tag

                        dbConnectedEquip.Rows.Add(sRow)
                    End If
                End If
            Next

            dgvSTSelectedEquipment.DataSource = New DataView(dbConnectedEquip)
            dgvSTSelectedEquipment.ClearSelection()

            dgvSTEquipmentAvail.CurrentCell = dgvSTEquipmentAvail(0, 0)
            dgvSTEquipmentAvail.ClearSelection()

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

        EH.ProcessMessages(frmCalibration_3, frmCalibration_3.sbr, EH.ErrorMessage)
    End Sub
End Class

Open in new window


Form Level routines

'This Sub is executed to initially load each instance of the DataGridView
    Public Sub LoadGrid_Equipment(ByVal iEquipmentType_ID As Integer, ByVal ue As userChannelEquipment, ByVal iChannel_ID As Integer)
        Try
            EH.ErrorMessage = String.Empty

            InitializeErrorClass(EH)
            BL.LoadGrid_Equipment(iEquipmentType_ID, iCalibration_ID, iChannel_ID, EH)

            If EH.ErrorMessage = String.Empty Then
                If EH.DataTable.Rows.Count > 0 Then
                    bsEquipmentGrid.DataSource = New DataView(EH.DataTable)
                    bsEquipmentGrid.Filter = "channel_ID = " & iChannel_ID

                    ue.dgvSTEquipmentAvail.DataSource = bsEquipmentGrid
                    ue.dgvSTEquipmentAvail.Columns(10).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(11).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(12).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(13).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(14).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(15).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(16).Visible = False
                    ue.dgvSTEquipmentAvail.Columns(17).Visible = False
                    ue.dgvSTEquipmentAvail.AutoGenerateColumns = True
                    ue.dgvSTEquipmentAvail.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
                Else
                    If iEquipmentType_ID = 0 Then
                        EH.ErrorMessage = "You have no Equipment defined...you cannot proceed!" & "~I"
                    Else
                        EH.ErrorMessage = "You have no Equipment defined for this type...you cannot proceed!" & "~I"
                    End If
                End If
            End If

        Catch ex As Exception
            EH.ErrorMessage = "frmCalibration_3/LoadGrid_Equipment() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try
    End Sub
   '
   '
   '
   '
   '
   'This Event controls the TabControl for which each UC resides on.
    Private Sub tabChannelEquipment_SelectedIndexChanged(sender As Object, e As EventArgs) Handles tabChannelEquipment.SelectedIndexChanged
        Try
            EH.ErrorMessage = String.Empty

            For Each uc In ucEquipment
                'MsgBox("uc.name is " & uc.Name & ", uc.tag is " & uc.Tag)
            Next

ProcessMessage:

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

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

userChannelEquipment-Images.docx
BlakeMcKennaAuthor Commented:
Here is a newer version of the Word document.
userChannelEquipment-Images.docx
BlakeMcKennaAuthor Commented:
Here is another important routine I forgot to add from previous post.

This routine is the Event generated by an AddHandler statment for each instance of the userChannelEquipment UC.

    Private Sub tabEquipment_Load(sender As Object, e As EventArgs)

        Dim ue As userChannelEquipment = DirectCast(sender, userChannelEquipment)

        Try
            EH.ErrorMessage = String.Empty

            LoadGrid_Equipment(iEquipmentType_ID, ue, ue.Tag)

            If EH.ErrorMessage = String.Empty Then
                LoadConnectedDevices(ue.dgvSTSelectedEquipment, ue.dgvSTEquipmentAvail, ue.Tag)
            End If

ProcessMessage:

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

        EH.ProcessMessages(Me, sbr, EH.ErrorMessage)
    End Sub

Open in new window

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.