本文介绍了在Windows应用程序中使用两个组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个组合框state和district,这些值是从数据库绑定的.当我根据所选项目区域选择状态时,必须显示

there are two combo boxs state and district, the values are bind from database. when i select state based upon selected item district has to display

推荐答案



Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
      If ComboBox1.SelectedItem.ToString() = "AP" Then
          ComboBox2.Items.Add("Medak")
 ComboBox2.Items.Add("Hyd")
'or bind combobox from db  also bind combobox2 here like  
 Dim cmd As SqlCommand = New SqlCommand()
        cmd.Connection = con
        cmd.CommandText = "select dist from district  where state='"+combobox1.selecteditem.tostring()+"'"
        con.Open()
        dr = cmd.ExecuteReader()
        If (dr.HasRows = True) Then
            While (dr.Read())
               ComboBox2.Items.Add(dr("dist").ToString())

            End While
        End If
        dr.Close()
        con.Close()
      End If

  End Sub


这篇关于在Windows应用程序中使用两个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:30