如何在核对表框中获取所选项目

时间:2015-01-09 11:18:10

标签: vb.net

我选中了checklistbox项目后,我制作了一个程序来填充checklistbox2。在这里我得到了结果,但过程采用了不同的方式。

问题是checklistbox2在checkedlistbox1中单击列表框3次时填充

Dim connection As New OleDbConnection("Data Source=xxx;Provider=xxxx; User Id=xxxx; Password=xxx")
        Dim dt2 As New DataTable
        Dim i As Integer
        For i = 0 To CheckedListBox1.Items.Count - 1 Step i + 1
            If CheckedListBox1.GetItemCheckState(i) = CheckState.Checked Then
                Dim xx As String = (CType(CheckedListBox1.Items(i), DataRowView))("name")
                Dim sqlstr2 As String = "xxxxxxxxxxxxxx"
                Dim command2 As New OleDbCommand(sqlstr2, connection)
                Dim adpt2 As New OleDbDataAdapter(command2)
                adpt2.SelectCommand = command2
                adpt2.Fill(dt2)
                CheckedListBox2.DataSource = dt2
                CheckedListBox2.DisplayMember = "name"
                CheckedListBox2.ValueMember = "name"
            End If
        Next

0 个答案:

没有答案