<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'combo box' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'combo box' posted on the 'C#' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2013 Programmers Heaven</copyright>
    <pubDate>Sat, 18 May 2013 22:43:15 -0700</pubDate>
    <lastBuildDate>Sat, 18 May 2013 22:43:15 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/429933/combo-box/</link>
      <description>Hi, I am creating a c# win form application.&lt;br /&gt;
&lt;br /&gt;
I have 2 comboboxes.&lt;br /&gt;
&lt;br /&gt;
One named suppliercombobox, the other named contactcombobox.&lt;br /&gt;
&lt;br /&gt;
In my C# application I have a sql database linked in. &lt;br /&gt;
&lt;br /&gt;
1 Supplier can have many contacts, one contact can only work for one supplier. &lt;br /&gt;
&lt;br /&gt;
Below is the code which puts the values in the combobox suppliercombobox:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblsupplier", con);

            DataTable dt = new DataTable();
            da.Fill(dt);

            for (int i = 0; i &amp;lt; dt.Rows.Count; i++)
            {
                SupplierComboBox.Items.Add(dt.Rows[i]["SupplierNam
e"]);
            }
            con.Close();
        }
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
This code is called on the page load event, and works fine.&lt;br /&gt;
&lt;br /&gt;
My code to put the values in the contact combo box is:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;

            con.Open();
            
            string supid = SupplierComboBox.SelectedIndex.ToString();
            MessageBox.Show(supid);
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM tblsuppliercontact WHERE supplierid= '"+ supid +"'", con);
            DataTable dt = new DataTable();
            dt.Rows.Clear(); 
            
            dt.Clear();
            da.Fill(dt);

            for (int i = 0; i &amp;lt; dt.Rows.Count; i++) // put a breakpoint here and look at the table it the datatable, it is the correct data but is not showing correclty in the listbox.
            { 
                ContactcomboBox.Items.Add(dt.Rows[i]["ContactFirst
Name"]);
            }
            da = null;
            dt.Rows.Clear();
            con.Close();

&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
This code called when the text changes in the supplier combo box. Initially it will load the contacts for the correct supplier, but if I change the supplier again, the contact combo box will display the contacts from BOTH of the suppliers. &lt;br /&gt;
&lt;br /&gt;
I have tried using dt.rows.clear(); and dt.clear(); in various places.&lt;br /&gt;
&lt;br /&gt;
I would like to know how to get the contact combo box working as I descibed (to only show the contacts from the selected supplier).&lt;br /&gt;
&lt;br /&gt;
I would also like to know how to display both the contacts firstname and surname in the combo drop down box.&lt;br /&gt;
&lt;br /&gt;
I am very new to c# so unsure if I am approaching this correctly, please ask if you need to know anything else, any help is greatly appreiciated, I've been stuck on this a while now.&lt;br /&gt;
&lt;br /&gt;
Many Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/429933/combo-box/</guid>
      <pubDate>Thu, 25 Oct 2012 13:40:30 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/430048/re-combo-box/#430048</link>
      <description>Any suggestions are appreciated. &lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/430048/re-combo-box/#430048</guid>
      <pubDate>Thu, 01 Nov 2012 06:28:44 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/430161/re-combo-box/#430161</link>
      <description>still having problems if anyone knows the solution.&lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/430161/re-combo-box/#430161</guid>
      <pubDate>Thu, 08 Nov 2012 03:58:02 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/430164/re-combo-box/#430164</link>
      <description>Hi, you need to clear the combobox before you loop and reload.&lt;br /&gt;
&lt;br /&gt;
e.g. ComboBox.Items.Clear()&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/430164/re-combo-box/#430164</guid>
      <pubDate>Thu, 08 Nov 2012 05:38:08 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/430177/re-combo-box/#430177</link>
      <description>Rather than looping through your datatable you can just bind it to your dropdownlist, which will be faster, and easier &lt;img src="http://www.programmersheaven.com/images/Community/smile.gif" width="15" height="15" alt="" /&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
e.g.&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
//set datasource of combo to dt
ContactcomboBox.DataSource = dt;

//set the text and value fields
ContactcomboBox.DataTextField = "ContactFirstName";
ContactcomboBox.DataValueField = "ContactFirstName";

//bind the data to the combo
ContactcomboBox.DataBind();

//add a blank first row to the combo (optional)
ContactcomboBox.Items.Insert(0,new ListItem(string.Empty, string.Empty);

//set the selected value to the first list value (optional)
ContactcomboBox.SelectedIndex = 0;
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/430177/re-combo-box/#430177</guid>
      <pubDate>Fri, 09 Nov 2012 00:46:42 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/430178/re-combo-box/#430178</link>
      <description>Quick correction, that code was for a dropdownlist is ASP.net / C# for Combobox on a form you need slightly different:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="sourcecode"&gt;
//set datasource of combo to dt
ContactcomboBox.DataSource = dt;

//set the display text
ContactcomboBox.DisplayMember = "ContactFirstName";

//set the selected value to the first list value (optional)
ContactcomboBox.SelectedIndex = 0;
&lt;/pre&gt;&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/430178/re-combo-box/#430178</guid>
      <pubDate>Fri, 09 Nov 2012 01:10:13 -0700</pubDate>
      <category>C#</category>
    </item>
    <item>
      <title>Re: combo box</title>
      <link>http://www.programmersheaven.com/mb/csharp/429933/430181/re-combo-box/#430181</link>
      <description>Thank you for the help, I will try this over the weekend and let you know if it works. &lt;br /&gt;
&lt;br /&gt;
Thanks&lt;br /&gt;
&lt;br /&gt;
Andy&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/csharp/429933/430181/re-combo-box/#430181</guid>
      <pubDate>Fri, 09 Nov 2012 02:50:59 -0700</pubDate>
      <category>C#</category>
    </item>
  </channel>
</rss>