在comboBox选择值后,textBox自动显示与comboBox相连接的值!

2025-05-05 21:35:46
推荐回答(2个)
回答1:

获取combobox的change事件,事件类型是IndexChangeEvent,然后再事件方法中根据combobox选择的条目信息判断label的文本变化就可以了,这个问题查flex api是可以解决的


xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955" minHeight="600">


import mx.collections.ArrayCollection;

import spark.events.IndexChangeEvent;

[Bindable]
public var cards:ArrayCollection = new ArrayCollection(
[ ,
]);

protected function combobox2_changeHandler(event:IndexChangeEvent):void
{
//中文
if(cb.selectedItem.data == 1)
{
ac.text = "中文";
}
//English
else
{
ac.text = "English";
}
}

]]>










回答2:

你可以把绑定写到外面:
public void ComBind()
{String MySQLConnectionString = global::WindowsFormsApplication1.Properties.Settings.Default.testConnectionString;
string MySQL = "SELECT DISTINCT a3 FROM test1 WHERE (a2 ='" + this.comboBox1.Text + "')";
SqlConnection MyConnection = new SqlConnection(MySQLConnectionString);
MyConnection.Open();
System.Data.DataTable MyTable = new System.Data.DataTable();
SqlDataAdapter MyAdapter = new SqlDataAdapter(MySQL, MyConnection);
MyAdapter.Fill(MyTable);

this.comboBox1.DataSource = MyTable;
this.comboBox1.DisplayMember = "a2";
this.comboBox1.ValueMember = "a3";
if (MyConnection.State == ConnectionState.Open)
{
MyConnection.Close();
}
}
ptotect void com_select(object sender,eventargs e)
{
textbob.text=combox.comboBox1.SelectedValue.ToString();
ComBind();
}
理论上你的那种做法是没有错误的。
如果不行,你换这个试试~!