如题,如combobox中有下列项目
value text
 1    语文
 2    数学
 3    英语当选择combobox中语文时,textboxd的值变为1该如何做啊?

解决方案 »

  1.   

    你的Combobox是绑定的数据库吗中的数据吗?
      

  2.   

    WebForm无此问题,在Winform中如果是绑定数据源,就将DisplayMember和ValueMember分别对应为Text和Value,如果是通过Add方法将一般对象添加到列表中,则重写对象的ToString方法,显示的Text就是这个方法的返回值,Value应是对象的某个属性。
      

  3.   

    comboBox.SelectedIndex
    comboBox.SelectedValue
      

  4.   

    给你写个绑定的例子:建数据库:
    create database student;use student;create table Item
    ( id int,
    name varchar(20)
    )
    insert into Item values(1,'语文');
    insert into Item values(2,'数学');
    insert into Item values(3,'英语');代码:
    //引入
    using System.Data.SqlClient;操作代码:
    private void Form1_Load(object sender, EventArgs e)
            {
                DataBind();
            }
            //数据绑定
            private void DataBind()
            {
                SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
                SqlDataAdapter sda = new SqlDataAdapter("select * from Item", con);
                DataSet ds = new DataSet();
                sda.Fill(ds, "Item");
                this.comboBox1.DataSource = ds.Tables["Item"];
                this.comboBox1.DisplayMember = "name";
                this.comboBox1.ValueMember = "id";
            }
            private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
            {
                if (this.comboBox1.SelectedItem != null)
                {
                    this.textBox1.Text = this.comboBox1.SelectedValue.ToString();
                }
            }
      

  5.   

    private void comboBox1_SelectedItemChanged(object sender, EventArgs e)
    {
    this.textBox1.Text = this.comboBox1.SelectedIndex.ToString();
    }