private void Form_AddMember_Load(object sender, EventArgs e)
        {
            da.SelectCommand = new SqlCommand("SELECT * from dbo.membership_details", cs);
            DataSet ds = new DataSet();
            da.Fill(ds, "membership_details");
            comboBox1.DataSource = ds.Tables["membership_details"];
            comboBox1.DisplayMember = "membership_desc";
            comboBox1.ValueMember = "membershiptype_id";
             da.SelectCommand = new SqlCommand("select membership_fees from dbo.membership_details where membership_desc='" + comboBox1.SelectedValue + "'", cs);
                    SqlCommand cmd = new SqlCommand("select membership_fees from dbo.membership_details where membership_desc='" + comboBox1.SelectedValue + "'", cs);
                    da.Fill(ds, "membership_details.membership_fees");
                    textBox7.DataBindings.Add(new Binding("Text", ds, "membership_details.membership_fees"));

private void comboBox1_SelectedIndexChanged_1(object sender, EventArgs e)
        {
            da.SelectCommand = new SqlCommand("select membership_fees from dbo.membership_details where membership_desc='" + comboBox1.SelectedValue.ToString()+ "'", cs);
            da.Fill(ds, "membership_details.membership_fees");
            textBox7.Text = comboBox1.SelectedValue.ToString();

combobox1=membership_desc
textbox7=fees(automatically)
Suggest me what i m missing here....THe data is fixed it is not changing as i change values of combobox...

Why do you use

comboBox1.SelectedValue;

?
Is there any particular reason? YOu would like to get thw ValueMember out of it, am I right?

Edited 5 Years Ago by Mitja Bonca: n/a

Heres an example how you have to use comboBox`s selectedValue method to get the actual Value (this is the ValueMember of the dataSurce, and the DisplayMember):

public Form1()
        {
            InitializeComponent();
            DataTable table = new DataTable("MyTable");
            DataColumn[] columns = new DataColumn[] { 
               new DataColumn("Id", typeof(int)), 
               new DataColumn("Name", typeof(string)) };
            table.Columns.AddRange(columns);

            table.Rows.Add(1, "Mitja");
            table.Rows.Add(2, "Nataška");
            table.Rows.Add(3, "Karmen");

            comboBox1.DataSource = table;
            comboBox1.DisplayMember = "Name";
            comboBox1.ValueMember = "Id";

            //if you will add the event in a form designer, this event will fire while data binding, and you will get an error.
            //so you do as I do here - code order, and adding the event here bellow!
            this.comboBox1.SelectedIndexChanged += new EventHandler(comboBox1_SelectedIndexChanged);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int intID = (int)comboBox1.SelectedValue;
            //string strId = comboBox1.SelectedValue.ToString();
            string strName = comboBox1.Text;
            MessageBox.Show("User`s ID is: " + intID + "\nHis name is: " + strName);
        }
This article has been dead for over six months. Start a new discussion instead.