Hi Guys

I want to change the values in first combo box1 according to values in combo box2.I wore followign coding but it did nt work.I wrote in under SelectedIndexChanged in combo box
Pls give me idea how to slove this problem

private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {   
            SqlConnection con = new SqlConnection("Data Source=IT-TEMP;Initial Catalog=Test;Integrated Security=True");
            string str3 = "Select ExecutiveCode from dbo.Executive where TerritoryCode='"+ this.comboBox2.Text +"'";
          
            con.Open();
            SqlCommand command3 = new SqlCommand(str3, con);
            SqlDataReader reader = command3.ExecuteReader();
            comboBox1.Refresh();
          
            while (reader.Read())
            {

               this.comboBox1.Items.Add(reader[0].ToString());


            }

Thanks

Recommended Answers

All 5 Replies

Try looking at the selectedIndex item

also before adding the items, make sure you call

this.comboBox1.Items.Clear();

Hi

Thanks for reply from dickersonka and Lizr.But still problem is there.Once I did what dickersonka mentioned above ,but no value change in first combo box

Are you sure 'this.comboBox2.Text ' returns the selected index, (and do you need value or text)?

And make sure that reader[0].ToString() returns the intended value? You may print or debug..

Also, as dickersonka said, clear the combobox not refresh.

As I said, you need to look at the selected information..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.