ComboBox上的“SelectedValueChanged”事件处理 [英] 'SelectedValueChanged' Event Handling on ComboBox

查看:1112
本文介绍了ComboBox上的“SelectedValueChanged”事件处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个组合框命名

 comBoxName,
comBoxContact,
comBoxAddress,
comBoxFunction,





我已经从访问DataBase绑定了组合框的数据。

现在我想在comBoxName上使用SelectedValueChanged事件,当我从列表中选择一个名称,它会根据

 comBoxContact,
comBoxAddress,
comBoxFunction,

解决方案

 private void combobox_name_SelectedIndexChanged(object sender,EventArgs e)
{
OdbcConnection con = new OdbcConnection(ConnectionString);
con.Open();

combobox_contact.Items.Clear();
combobox_address.Items.Clear();
combobox_function.Items.Clear();

string SQLQuery =从信息中选择联系人,地址,函数,其中name ='+ combobox_name.Text +';

OdbcDataAdapter da1 = new OdbcDataAdapter(SQLQuery,con);

da1.Fill(ds);

combobox_contact.DataSource = ds.Tables [0];
combobox_contact.DisplayMember =联系;

combobox_address.DataSource = ds.Tables [0];
combobox_address.DisplayMember =address;

combobox_function.DataSource = ds.Tables [0];
combobox_function.DisplayMember =function;

//如果要设置值成员使用此代码

combobox_contact.ValueMember =Contact;


}





我希望这能帮助你,回复我...... .......


i have 4 combo boxes naming

comBoxName,
comBoxContact,
comBoxAddress,
comBoxFunction,



I have bind the data of combo box from access DataBase.
Now i want to use SelectedValueChanged event on comBoxName, when i select a name from the list it automatically select the data against the Name contaning in

comBoxContact,
comBoxAddress,
comBoxFunction,

解决方案

private void combobox_name_SelectedIndexChanged(object sender, EventArgs e)
        {
	    OdbcConnection con = new OdbcConnection(ConnectionString);
	    con.Open();

            combobox_contact.Items.Clear();
	    combobox_address.Items.Clear();
            combobox_function.Items.Clear();

            string SQLQuery = "Select contact, address,function from Information where name='"+combobox_name.Text+"' ";
            
	    OdbcDataAdapter da1 = new OdbcDataAdapter(SQLQuery, con);

            da1.Fill(ds);

            combobox_contact.DataSource = ds.Tables[0];
            combobox_contact.DisplayMember = "Contact";

	    combobox_address.DataSource = ds.Tables[0];
	    combobox_address.DisplayMember = "address";

	    combobox_function.DataSource = ds.Tables[0]; 
            combobox_function.DisplayMember = "function";

	    // if you want to set value member use this code

            combobox_contact.ValueMember = "Contact";
            

        }



I hope this will help you ,REPLY ME............


这篇关于ComboBox上的“SelectedValueChanged”事件处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆