C#,winform形式下 2个combobox 互相联动---数据库access
来源:互联网 发布:php 面向切面编程 编辑:程序博客网 时间:2024/05/22 21:39
参考文章:
1,http://topic.csdn.net/u/20091027/16/b804ebc8-c88c-4c05-9652-d198d4b4f0fb.html
private void Form1_Load(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("select * from department",con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
con.Close();
comboBox1.DataSource = dt;
comboBox1.DisplayMember = "department";
comboBox1.ValueMember = "departmentId";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex>-1)
{
DataRowView drv = (DataRowView)comboBox1.SelectedItem;
int id = Convert.ToInt32(drv.Row["departmentId"].ToString());
SqlConnection con = new SqlConnection(conn);
con.Open();
SqlCommand cmd = new SqlCommand("select * from major where departmentId='" + id + "'", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
comboBox2.DataSource = dt;
comboBox2.DisplayMember = "major";
comboBox2.ValueMember = "majorId";
}
2,
http://blog.csdn.net/gaofeng2000/archive/2009/05/06/4156247.aspx
ComboBox的SelectionChangeCommitted事件
实现方案:
在ComboBox的SelectionChangeCommitted事件 写 联动取数:
private void comBox_subject_SelectionChangeCommitted(object sender, System.EventArgs e)
{
if (comBox_subject.SelectedIndex > -1)
{
DataRowView drv = (DataRowView)comBox_subject.SelectedItem;
String check_subject = drv.Row["学科"].ToString();
string connectionStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + System.Windows.Forms.Application.StartupPath + "/teachdb.mdb";
OleDbConnection conn = new OleDbConnection(connectionStr);
conn.Open();
string strsubject = "select distinct 出版社 from presstable where 学科='" + check_subject + "'";
OleDbDataAdapter MyAdapter1 = new OleDbDataAdapter(strsubject, conn);
DataSet ds = new DataSet();
MyAdapter1.Fill(ds, "press");
comBox_Press.DataSource = ds.Tables["press"].DefaultView;
comBox_Press.DisplayMember = "出版社";
comBox_Press.ValueMember = "出版社";
conn.Close();
}
}
3
http://www.cnblogs.com/luoht/archive/2010/02/25/1673737.html
两个ComboBox互相联动的一种解决方法
今天工作中遇到一个头疼到问题就是两个comboBox互相联动绑定,开始用comboBox1_SelectedIndexChanged事件,结果两个comboBox不停的相互绑定,死循环了
后来发现微软还提供了一个comboBox1_DropDownClosed事件:当关闭组合框下拉部分时发生,当用程序改变SelectedIndex时就不会出现两个comboBox相互改对方到Index并触发comboBox1_SelectedIndexChanged,
后来将SelectedIndexChanged事件全部换成DropDownClosed,就可以实现两个comboBox互相联动了;
TextChanged事件和TextUpdate也是一个对用程序改变其值敏感,一个不敏感。
- C#,winform形式下 2个combobox 互相联动---数据库access
- c#ComboBox的联动
- C#ComboBox的联动
- Winfrom c# 两个ComboBox互相联动
- Winform-NumericUpDown和ComboBox年月日时联动
- c#(winform)中ComboBox和ListBox添加项 键值对 形式
- winform combobox绑定多个字段
- ComboBox联动
- combobox联动
- Winform连接access数据库操作
- Winform连接access数据库操作
- 利用winform 操作access 数据库
- C#:关于WinForm中ComboBox的探究
- C#(WinForm) ComboBox和ListBox添加项
- LightSwitch how to realize two combobox linkage(如何实现2个下拉框联动)
- WinForm下ComboBox设定SelectedValue总结
- winform下ComboBox的绑定问题
- winForm ComboBox
- VS与Win7共舞:UAC惹祸 如何进行安装程序检测?
- 通用存储过程
- 浅析symbian中RFileLogger用法(2010-02-21 13:22:57)
- 使用SwingWorker之三
- vc笔记二
- C#,winform形式下 2个combobox 互相联动---数据库access
- Finalize、Dispose、Close 的区别与使用[C#基础]
- 天气
- 开始了额哈库拉
- 【摘自网易博客】FireFox与IE中CSS兼容技术集绵整理
- 网页开发资料网站
- 程序与数学
- 【转】鼠标形状
- JDBC连接数据库(转载)