How to refresh Combobox items

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Dec 2008
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

 
0
  #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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,925
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 276
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: How to refresh Combobox items

 
0
  #2
Jan 5th, 2009
A form doesn't close by itself. Could you send your code with the eventhandler of the button?
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
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: How to refresh Combobox items

 
0
  #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 Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: How to refresh Combobox items

 
0
  #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

  1. using System.Data.SqlClient;
  2.  
  3.  
  4. namespace TestDummyTWO
  5. {
  6. public partial class Form1 : Form
  7. {
  8. SqlConnection sqlcon =
  9. new SqlConnection("Data Source=.;Initial Catalog=your_table;Integrated Security=True;Asynchronous Processing = True");
  10.  
  11. SqlCommand sqlCom = new SqlCommand("SELECT ITEMS FROM YOUR_TABLENAME");
  12.  
  13. public Form1()
  14. {
  15. InitializeComponent();
  16. }
  17.  
  18. private void Form1_Load(object sender, EventArgs e)
  19. {
  20. SqlDataReader reader = sqlCom .ExecuteReader();
  21.  
  22. // Looping throuhg the list of data
  23. while (reader.Read())
  24. {
  25. // Fill combo Box with data
  26. comboBox1.Items.Add(reader["ITEMS"]);
  27. }
  28. }
  29.  
  30. private void button1_Click(object sender, EventArgs e)
  31. {
  32. // you added the new item from the tex box into the DATA TABLE
  33. // Not the combobox
  34. // use sqlCom again to do so
  35.  
  36. sqlCom.CommandText = "Insert into blah blah";
  37.  
  38. /* THIS IS WHAT YOU HAVE TO DO */
  39. sqlcon.Close();
  40. sqlcon.Open();
  41. }

Hope that helps ...
Last edited by cVz; Jan 6th, 2009 at 4:11 am.
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
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

 
0
  #5
Jan 7th, 2009
Hi
Thanks alot. it worked for me
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: How to refresh Combobox items

 
0
  #6
Jan 7th, 2009
Cooooollll
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
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