RSS Forums RSS

How to refresh Combobox items

Please support our C# advertiser: DiscountASP.NET – 3 Months Free on C# Web Hosting
Thread Solved
Reply
Posts: 13
Reputation: nmakkena is an unknown quantity at this point 
Solved Threads: 0
nmakkena nmakkena is offline Offline
Newbie Poster

How to refresh Combobox items

  #1  
Jan 5th, 2009
Hi

I am populating my combobox with table's data (example table name is "ITEMS" and table is having only one column and that is displayed as combobox items). In my form i am having i combobox,button and textbox. I will enter a new item in textbox and if i click on button, that new item will be stored in a table i.e. "ITEMS"). my problem is that new item has to be displayed in combobox items without closing my form and again opening it.
If i click button by entering new item in textbox that value has to be stored in table and combobox has to be populated with new item.

Thanks
AddThis Social Bookmark Button
Reply With Quote  
Posts: 1,222
Reputation: ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice ddanbe is just really nice 
Solved Threads: 163
ddanbe's Avatar
ddanbe ddanbe is online now Online
Nearly a Posting Virtuoso

Re: How to refresh Combobox items

  #2  
Jan 5th, 2009
A form doesn't close by itself. Could you send your code with the eventhandler of the button?
"If you judge people, you have no time to love them." Mother Teresa
Make love, no war. Cave ab homine unius libri.
First rule of debugging: "If you get a different error message, you're making progress."
Danny
Reply With Quote  
Posts: 1,734
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 184
LizR LizR is offline Offline
Posting Virtuoso

Re: How to refresh Combobox items

  #3  
Jan 5th, 2009
When you "open" the form, include as part of the calling to open method an update of your combobox items.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote  
Posts: 117
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 6
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: How to refresh Combobox items

  #4  
Jan 6th, 2009
Yo dude, you can always just refresh the connection, you don't need to close your form,

i take it you want something like this

using System.Data.SqlClient;


namespace TestDummyTWO
{
    public partial class Form1 : Form
    {
        SqlConnection sqlcon =
            new SqlConnection("Data Source=.;Initial Catalog=your_table;Integrated Security=True;Asynchronous Processing = True");

        SqlCommand sqlCom = new SqlCommand("SELECT ITEMS FROM YOUR_TABLENAME");

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            SqlDataReader reader = sqlCom .ExecuteReader();

            // Looping throuhg the list of data
            while (reader.Read())
            {
                // Fill combo Box with data
                comboBox1.Items.Add(reader["ITEMS"]);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            // you added the new item from the tex box into the DATA TABLE
            // Not the combobox
            // use sqlCom again to do so

            sqlCom.CommandText = "Insert into blah blah";

            /* THIS IS WHAT YOU HAVE TO DO */
            sqlcon.Close();
            sqlcon.Open();
        }

Hope that helps ...
Last edited by cVz : Jan 6th, 2009 at 3:11 am.
Delphi & C# programmer deluxe...
Reply With Quote  
Posts: 13
Reputation: nmakkena is an unknown quantity at this point 
Solved Threads: 0
nmakkena nmakkena is offline Offline
Newbie Poster

Re: How to refresh Combobox items

  #5  
Jan 6th, 2009
Hi
Thanks alot. it worked for me
Reply With Quote  
Posts: 117
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 6
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: How to refresh Combobox items

  #6  
Jan 7th, 2009
Cooooollll
Delphi & C# programmer deluxe...
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 2072 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:32 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC