Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

Using C# and SQL Database.

i have a Form which Contains some customer information. In which i have a textbox for customer name. the textbox have automcomplete function when i am adding a new customer name in this text box the customer name save in the database. Now, next time i want to see this customer name in autocomplete function without closing the form.

so how to update or refresh or reloding form in c#.
Posted
Comments
tanweer 27-Sep-13 8:27am    
please post your code here that load users
indiancodinglove 27-Sep-13 9:11am    
private void Item_Load(object sender, EventArgs e)
{
Autocomplete();
}

private void Autocomplete()
{
//Autocomple Name here
try
{
string query = "Select distinct txtItemCode from ItemTable order by txtItemCode asc";
SqlConnection conn = new SqlConnection(connstr);
SqlCommand cmd = new SqlCommand(query, conn);

conn.Open();
SqlDataReader dReader = cmd.ExecuteReader();
AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
while (dReader.Read())
{
namesCollection.Add(dReader["txtItemCode"].ToString());
}
dReader.Close();
conn.Close();
txtItemCode.AutoCompleteMode = AutoCompleteMode.Suggest;
txtItemCode.AutoCompleteSource = AutoCompleteSource.CustomSource;
txtItemCode.AutoCompleteCustomSource = namesCollection;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
MCY 27-Sep-13 9:35am    
why not add the new customer to namesCollection after you inserted it to database?

1 solution

Are you trying to refresh just the textbox so that it will go get the new data without opening it again? Or do you want to refresh the entire form?

If you want to just refresh the textbox, just rebind it after you add, edit, or delete. This should reload the textbox with the updated data...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900