none
multiselect listbox getting the info and using it RRS feed

  • Question

  • Need help please

    what I have is a form that has a dropdown box for the projects and one for the companies.  Select a project and then multiselect companies.  In construction, you have a project(job) and you have multiple subcontractors(companies).  I want to be able to use the listbox to quickly select them for a project and add them to a table that has "PtblProjectID" PtblCompanyID" for use in other items like reports or lists.

    My code:


        Private Sub FindAllOfMyString2(ByVal searchString As String)
            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
            Dim xName As String
            xPR = CType(PtblProjectIDComboBox.SelectedValue, String)
            xPR = CType(Convert.ToInt32(xPR), String)
            xselected = CType(PtblCompanyIsSelectedCheckBox.Checked, Boolean)
            For i = 0 To ListBox1.SelectedIndices.Count - 1
                If i > -1 Then
                    xCR = ListBox1.SelectedIndices(i).ToString  'NEED actual company ID not getting it this way
                    xselected = True
                    TableGroupProjectTableAdapter.Insert(CType(xPR, Integer?), CType(xCR, Integer?), CType(xselected, Boolean), CType(xName, String)) 'add the record if it is valid        
                    TableAdapterManager.UpdateAll(Me.CMDB1copy2DataSet)
                End If
            Next

        End Sub


    Saturday, April 27, 2019 10:54 PM