0

我有 2 combobox。两个comboBox值都来自dataset

cb1包含数字列表eg : 10, 20, 30
cb2包含数字列表eg : 10.2, 11.3, 20.5, 24.8, 34.5

Cb2必须在选择 cb1 时过滤列表

例如:10 -> 10.2,11.3 20 -> 20.5, 24.8 30 -> 34.5

如何使用 vb.net 对这些进行编码?我正在使用 mssql,所有数据都存储在表和 Visual Studio 2005 vb.net 中

cb1 = BilletSize
cb2 = BilletUnitWt

编辑

到目前为止尝试的代码

Private Sub cbBilletSize_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbBilletSize.SelectedIndexChanged 
    Dim SqlStr As String SqlStr = "SELECT tbBilletUnitWt.BilletUnitWtCode FROM tbBilletUnitWt WHERE tbBilletUnitWt.BilletSizeCode = " & Me.cbBilletSize.SelectedValue & ";" 
    Me.cbUnitWt.SelectedValue.RowSource = SqlStr Me.cbUnitWt.SelectedValue.Requery()
End Sub
4

1 回答 1

0

我用列表而不是数据集快速尝试了这个。你能看看你是否可以调整它以使其适合你吗?

我认为您应该主要只需将列表操作替换为等效的数据集操作...

Public Class Form1

    Dim combobox1Items As List(Of Integer) = New List(Of Integer)
    Dim combobox2Items As List(Of Double) = New List(Of Double)

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        Me.combobox1Items.Add(10)
        Me.combobox1Items.Add(20)
        Me.combobox1Items.Add(30)

        Me.combobox2Items.Add(10.2)
        Me.combobox2Items.Add(11.3)
        Me.combobox2Items.Add(20.5)
        Me.combobox2Items.Add(24.8)
        Me.combobox2Items.Add(34.5)

        With Me.ComboBox1
            .DataSource = Me.combobox1Items
        End With

    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged

        Dim bindingList As New List(Of Double)

        For Each item As Double In Me.combobox2Items
            If item > CInt(Me.ComboBox1.Items(Me.ComboBox1.SelectedIndex)) Then
                Call bindingList.Add(item)
            End If
        Next

        With Me.ComboBox2
            .DataSource = bindingList
        End With

    End Sub

End Class
于 2013-02-27T03:12:55.173 回答