首页新闻找找看学习计划

关于vb.net ComboBox控件 ValueMember和SelectedValue的用法问题

0
悬赏园豆:5 [待解决问题]

今天遇到个问题:
我需要查询SQL中的数据实现多个ComboBox级联, cboNozStyle.ValueMember = mItem("MinorCd").ToString() 也获取到了值,但是第二级我使用
cboNozStyle.SelectedValue.ToString取出来的确是空值!有人知道如何解决吗!

'第一级
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    cboNozStyle.Items.Clear()
    Dim dal As SqlHelper1 = New SqlHelper1()
    Dim Sqltext As String = "select * from NozStyle Where StatusYn Like 'Y'"
    Dim dtUser = dal.QueryNo(Sqltext, CommandType.Text)
    If dtUser.Rows.Count > 0 Then
        For Each mItem As DataRow In dtUser.Rows
            cboNozStyle.Items.Add(mItem("MinorTransNm").ToString()) '下拉菜单中显示类型
            cboNozStyle.ValueMember = mItem("MinorCd").ToString() '将类型ID保存到ComboBox的隐藏值中
        Next
    End If
End Sub



'第二级
Private Sub cboNozStyle_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboNozStyle.SelectedIndexChanged
    cboNozSize.Items.Clear()
    Dim dal As SqlHelper1 = New SqlHelper1()
    Dim Sqltext As String = "select t1.MinorTransNm,t1.MinorCd from NozSize as t1 where t1.RelCd1='" + cboNozStyle.SelectedValue.ToString + "'"
    Dim dtUser = dal.QueryNo(Sqltext, CommandType.Text)
    If dtUser.Rows.Count > 0 Then
        For Each mItem As DataRow In dtUser.Rows
            cboNozSize.Items.Add(mItem("MinorTransNm").ToString())
            cboNozSize.ValueMember = mItem("MinorCd").ToString()
        Next
    End If
End Sub
guitarboy的主页 guitarboy | 初学一级 | 园豆:190
提问于:2019-12-02 17:53
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册