在Windows应用程序中使用两个组合框 [英] using two combo box in windows application
本文介绍了在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
推荐答案
请参考:这与源代码完全相同.
创建级联DropDownLists [ C#-级联组合框会在Windows中出现 [ ^ ]
层叠组合框会生成Windows [如何做Windows应用程序中的级联组合框 [
Please refer: This is exact one with source code.
Creating Cascading DropDownLists[^]
This article explains you how to create a Cascading DropDownLists in ASP.Net that is DropDownLists which depend on the previous or parent DropDownList for the data.
C# - Cascading combo box results in a Windows[^]
Cascading combo box results in a Windows[^]
Similar discussion: How to do cascading combobox in windows application[^]
我认为,以下帖子可以为您提供帮助:
http://stackoverflow.com/questions/10239392/c-sharp- combobox-options-dependent-on-another-combobox [ ^ ]
http://stackoverflow.com/questions/4635217/one-combobox- [-a-other-combobox-in-wpf [ ^ ]
I think, the following posts can help you:
http://stackoverflow.com/questions/10239392/c-sharp-combobox-options-dependent-on-another-combobox[^]
http://stackoverflow.com/questions/4635217/one-combobox-dependent-on-other-combobox-in-wpf[^]
像这样尝试
try like this
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应用程序中使用两个组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文