我有2 combobox
。 comboBox
值均来自dataset
。
cb1
包含数字列表eg : 10, 20, 30
cb2
包含数字列表eg : 10.2, 11.3, 20.5, 24.8, 34.5
Cb2
列表
例如:10 - > 10.2,11.3 20 - > 20.5,24.8 30 - > 34.5
如何使用vb.net编码? Im uisng 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
答案 0 :(得分:0)
我快速尝试使用列表而不是数据集。你能看出你是否能够适应它以使它适合你?
我认为你应该大多只需要用等效的数据集操作替换list操作......
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