我有一张上面的表格。我的问题简而言之就是:我想从下拉列表中选择一个项目 #,然后从 ListBox 中选择多家公司。并将它们添加到表格中,即project#, company#
。我有一个项目表和另一个公司表。我为链接的项目/公司设置了一个表格来保存记录。您可以让多家公司参与 1 个项目。
有人可以帮忙吗?
我的代码是:
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
输入表单的截图: