| | |
How to refresh Combobox items
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Dec 2008
Posts: 13
Reputation:
Solved Threads: 0
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
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
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
Hope that helps ...
i take it you want something like this
C# Syntax (Toggle Plain Text)
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 4:11 am.
Delphi & C# programmer deluxe...
![]() |
Similar Threads
- Contactless Card Reader problem (VB.NET)
- Popup Form Refresh combobox on parent form (VB.NET)
- How to clear or refresh a combo box? (VB.NET)
Other Threads in the C# Forum
- Previous Thread: update access database
- Next Thread: Data collection from dataset using query
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development display draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql native networking operator path photoshop picturebox pixelinversion pixelminversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml






