How to utilize a multiselect ListBox to add data to a table

1

I have a form above. the short of my question is: I want to select a project # from dropdown, then select multiple companies from ListBox. And have them added to the table, i.e. project#, company#. I have one table for projects and another for companies. I have set up a table for linked projects/companies to keep the records in. You can have multiple companies involved in 1 project.

Could someone please help with this?

My code is:

Private Sub UpdateSelected()
    Dim xPR As String      'variable for project id to use same # for each data row insert
    Dim xCR As String      'variable for company id to use selected # for each data row insert
    Dim xselected As Boolean

    xPR = PtblProjectIDComboBox.SelectedValue
    xPR = Convert.ToInt32(xPR)

    For i = 0 To ListBox1.Items.Count - 1     'count to stroll thru company db and check if selected
        If ListBox1.GetSelected(i) = True Then      'if selected then add record project # and selected company#
            xCR = Convert.ToInt32(ListBox1.ValueMember)
            xselected = True
            TableGroupProjectTableAdapter.Insert(xPR, xCR, xselected)     'add the record if it is valid

            'update db
            Validate()
            TableAdapterManager.UpdateAll(CMDB1copy2DataSet)
        End If
    Next i
End Sub

Screenshot of the input form:

screenshot of input form

James W. Brumbaugh Sr.

Posted 2019-04-23T17:56:32.590

Reputation: 11

No answers