Reload the combo box after insert query?
I want to reload the combo box so that it would display the values recently entered by me. T开发者_JAVA百科he Language used is C#.Net 2005..I am making a windows application. Please guide me?
you just need to call the method .DataBind()
every time you want to "refresh" the combobox with new data
Save your last entered values, then load them when the comboBox is loaded. Something like:
private stirng _comboBoxSavedListPath = "";//or from application settings..
private List<string> _comboBoxLastEnteredValues = new List<string>();
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)//or whenever you want to save
{
if (comboBox1.SelectedIndex > -1)
{
string entry = comboBox1.SelectedItem.ToString();
if (!_comboBoxLastEnteredValues.Contains(entry))
{
_comboBoxLastEnteredValues.Add(entry);
}
}
}
Now handle the form Closing
event or just save the list again whenever item added. and load the list whenever form is loaded:
private void form1_Closing..
{
SaveList(_comboBoxLastEnteredValues);//Like(File.WriteAllLines(_comboBoxLastEnteredValues.ToArray(), _comboBoxSavedListPath);
}
private void form1_Load...
{
_comboBoxLastEnteredValues = LoadLastSavedList();//Like File.ReadAllLines(_comboBoxSavedListPath);
}
精彩评论