combobox 的使用问题,在线等
有两个COMBOBOX 控件comb_1,comb_2其中comb_1是在设计是定义好下拉项,我想在程序运行时,根据用户选择comb_1的某一行动态生成comb_2的下拉项,该如何写代码,请赐教 --------------------编程问答-------------------- 去GOOGLE上搜索一下有关JAVASCRIPT实现动态加载数据的源码,很多的.
如果WIN32,我想这个应该非常简单吧! --------------------编程问答-------------------- 当在一个combobox中选择项后会引发SelectedIndexChanged事件,在事件中访问SelectedItem属性可以获得选中的项。根据这个你可以控制另外一个combobox。 --------------------编程问答-------------------- 是WIN32程序,希望给出代码 --------------------编程问答-------------------- 2楼以经告诉你Win32的方法了。 --------------------编程问答--------------------
--------------------编程问答--------------------
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch ( comboBox1.SelectedIndex )
{
case 0 :
comboBox2.Items.Add("a");
comboBox2.Items.Add("b");
comboBox2.Items.Add("c");
break;
case 1:
comboBox2.Items.Add("q");
comboBox2.Items.Add("w");
comboBox2.Items.Add("e");
break;
case 2:
comboBox2.Items.Add("z");
comboBox2.Items.Add("x");
comboBox2.Items.Add("c");
break;
}
}
你comboBox的数据是从数据库中的到的吗? --------------------编程问答--------------------
Private Sub comb_1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_1.SelectedIndexChanged
With comb_2
.DataSource = 数据绑定
.DisplayMember = 字段值
.ValueMember = 字段code
End With
End If
End Sub --------------------编程问答-------------------- End If 去掉 --------------------编程问答-------------------- 写了个简单的窗体代码,搂主拿去试试.
Public Class Form1--------------------编程问答-------------------- 这么简单,lz不会? --------------------编程问答-------------------- 很简单吗 --------------------编程问答--------------------
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
Friend WithEvents ComboBox2 As System.Windows.Forms.ComboBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents Label2 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.ComboBox1 = New System.Windows.Forms.ComboBox
Me.ComboBox2 = New System.Windows.Forms.ComboBox
Me.Label1 = New System.Windows.Forms.Label
Me.Label2 = New System.Windows.Forms.Label
Me.SuspendLayout()
'
'ComboBox1
'
Me.ComboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox1.Location = New System.Drawing.Point(114, 40)
Me.ComboBox1.Name = "ComboBox1"
Me.ComboBox1.Size = New System.Drawing.Size(121, 20)
Me.ComboBox1.TabIndex = 0
'
'ComboBox2
'
Me.ComboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList
Me.ComboBox2.Location = New System.Drawing.Point(114, 88)
Me.ComboBox2.Name = "ComboBox2"
Me.ComboBox2.Size = New System.Drawing.Size(121, 20)
Me.ComboBox2.TabIndex = 0
'
'Label1
'
Me.Label1.Location = New System.Drawing.Point(15, 39)
Me.Label1.Name = "Label1"
Me.Label1.TabIndex = 1
Me.Label1.Text = "combox1:"
'
'Label2
'
Me.Label2.Location = New System.Drawing.Point(14, 87)
Me.Label2.Name = "Label2"
Me.Label2.TabIndex = 1
Me.Label2.Text = "combox2:"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(291, 174)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.ComboBox1)
Me.Controls.Add(Me.ComboBox2)
Me.Controls.Add(Me.Label2)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim cb2info(2) As String
For n As Integer = 0 To 2
cb2info(n) = ComboBox1.Text.Trim & n.ToString
Next
ComboBox2.Items.Clear()
ComboBox2.Items.AddRange(cb2info)
ComboBox2.SelectedIndex = 0
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cb1info As String() = {"a", "b", "c"}
ComboBox1.Items.Clear()
ComboBox1.Items.AddRange(cb1info)
ComboBox1.SelectedIndex = 0
End Sub
End Class
5 楼的写得不错的。转换一下就行了啊。
补充:.NET技术 , VB.NET