有一表a 有name 和 count 两个字段 ,comboBox1绑定的是name ,
根据comboBox1的选择结果,将对应的记录内容放到
text1.text
text2.text
谢谢。
根据comboBox1的选择结果,将对应的记录内容放到
text1.text
text2.text
谢谢。
解决方案 »
- listview控件取某行的某一列
- InvalidCastException: 将参数值从 SqlParameter 转换到 Guid 失败。]
- 【求助】WebBrowser控件的跨域访问
- 在绑定数据源的情况下,对datagridview的数据进行修改, 插入后, 然后再一次更新数据源.
- 高手帮忙!整数相乘问题
- 如何屏蔽掉开始菜单中的运行?急用,解决就结贴
- 用socket写web代理服务器,但是图像有问题!!
- api获取控件句柄以及内容的一些疑问
- 高手讨论,WIN98英文版的内码是什么,C#程序怎么实现在上面运行?
- 用什么工具写c#呢?
- 问个小问题:关于Remoting.
- 我想学学bindingsource是怎么回事,以下代码如何改
当combobox中的值被选定的时候,可以得到被选定的行的索引,对应的数组如 count[索引]就是count的值了
string str="select count from 表 where name='"+combobox1.text.trim()+"'";
conn.open();//conn在前应有定义
sqlcommand cmd=new sqlcommand(sql,conn);
cmd.CommandType = CommandType.Text;
string strCount = Convert.ToString(cmd.ExecuteNonQuery());
text2.text=strCount;
//没区分大小写
this.cbo .DataSource = Dataset.Table[0]//将cbo的数据源绑定到数据集
this.cbo .DisplayMember = "name"; //cbo的的显示层绑定name字段
this.cbo .ValueMember = "count"; //cbo的的数值层绑定count字段
//这样CBO的没一项都同时有两个值了 private void cbo_SelectedIndexChanged(object sender, EventArgs e)//cbo的索引变化引发的事件
{
this.text1.Text=this.cbo.text;
this.text2.Text=this.cbo.SelectedValue.ToString();
}
或者你不会用数据集,就用DataReade从数据库一条一条读出来,再加到Cbo的Items里面
private void PlaySet_Load(object sender, EventArgs e)
{
this.conndb();
da = new OleDbDataAdapter(@"select * from TwSoft ", dbconn);
DataSet ds = new DataSet();
da.Fill(ds, "TwSoft");
this.comboBox1.DataSource = ds.Tables["TwSoft"];
this.comboBox1.DisplayMember = "C_SoftName";
this.comboBox1.ValueMember = "C_SoftCount";
}
private void comboBox1_SelectionChangeCommitted(object sender, EventArgs e)
{
this.textBox1.Text= comboBox1.Text;
this.textBox2.Text = this.comboBox1.SelectedValue.ToString(); }
//我这样写有问题吗,为什么只有textbox2.text 与选择是同步的。textbox1的值却是上一次操作的。
_SelectedIndexChanged
你的
_SelectionChangeCommitted