Combo box and C#

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2008
Posts: 96
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Combo box and C#

 
0
  #1
Sep 10th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Combo box and C#

 
0
  #2
Sep 10th, 2008
Try looking at the selectedIndex item
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,162
Reputation: dickersonka will become famous soon enough dickersonka will become famous soon enough 
Solved Threads: 137
dickersonka dickersonka is offline Offline
Veteran Poster

Re: Combo box and C#

 
1
  #3
Sep 10th, 2008
also before adding the items, make sure you call

  1. this.comboBox1.Items.Clear();
Custom Application & Software Development
www.houseshark.net
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 96
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Re: Combo box and C#

 
0
  #4
Sep 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 49
Reputation: sivaslieko++ is an unknown quantity at this point 
Solved Threads: 0
sivaslieko++ sivaslieko++ is offline Offline
Light Poster

Re: Combo box and C#

 
1
  #5
Sep 11th, 2008
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.
Last edited by sivaslieko++; Sep 11th, 2008 at 2:30 am.
You see things; and you say 'Why?' But I dream things that never were; and I say 'Why not'
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Combo box and C#

 
0
  #6
Sep 11th, 2008
As I said, you need to look at the selected information..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC