Search code examples
vb.netwinformscheckboxtabsreal-time

How to run code in real time across multiple tabs, windows form, vb.net


I am currently programming in vb.net for a windows forms applications.

I have a windows form with multiple tabs and within each tab I have a DGV. Each DGV is connected to an sql server table, the same table across all tabs.

I want to use a check box to copy rows of data from the sql table to a specific tab. In this case I want to try and have this happen in real time, so without using a "refresh" button or something like that.

On each row in every tab I want the row of data to appear or disappear from the last tab depending on the status of the check box.

I have attached code and a picture. The code is used on the form load event to load the tables into the tabs. In the image you can see i want the rows to be loaded into the "ordered floors" tab after the check box has been checked.

Private Sub FormOrdered_Load(sender As Object, e As EventArgs) Handles Me.Load

    'load line 2 tab
    Try

        Using conn1 As New SqlConnection(connstring)
            conn1.Open()
            Using comm1 As SqlCommand = New SqlCommand("Select LineNumber, ShearNumber, JobNumber, FloorNumber, OrderedBy, DateOrdered, Ordered FROM Production.dbo.tblFCordered where LineNumber = 2", conn1)
                Dim da As New SqlDataAdapter
                da.SelectCommand = comm1
                da.Fill(Line2)

            End Using
            conn1.Close()
        End Using

        DataGridLine2.DataSource = Line2

    Catch ex As Exception
        MsgBox("Unable to make SQL Connection to load Line 2 Table, please contact an engineer!")
        MsgBox(ex.ToString)
    End Try

image


Solution

  • You could just clone the rows from the DGV when you check the checkbox and add them to the Ordered floors dgv.

    Something like:

    Private Sub CopyRows_CheckedChanged() Handles CopyRows.CheckedChanged
         For each r as DataGridViewRow in MyDGV.Rows
             dgvOrderedFloors.Rows.Add(r.Clone())
         next
    End Sub
    

    You'll have to modify this to suit obviously, but I think something along these lines should do what you want.

    Or you could clone the data tables you use for each datagridview, and add them to one master table which will be the datasource for your Ordered floors datagridview. That would be better, but might be more work upfront.