1
I have a combobox with some items added via form, by the property Items (Collection).
I wish I could leave it to the user to type new texts in this combobox, which in my case, is a combobox of product categories.
I created a code that adds the typed text to the combobox, but it does not remain there when the form is restarted, my question is, have how to add an item and make it remain in the items?
Note: There is no possibility for me to use database for this.
My code:
private void btnIncluirItens_Click(object sender, EventArgs e)
{
// para inserir na última posição
int cnt = cbCategoriaProduto.Items.Count;
if (cbCategoriaProduto.Text != String.Empty)
{
cbCategoriaProduto.Items.Insert(cnt, cbCategoriaProduto.Text);
}
else
{
cbCategoriaProduto.Items.Insert(cnt, "Item " + cnt);
}
cbCategoriaProduto.Text = ""; //limpa a caixa de texto após a inclusão
}
You want to save the inserted ones permanently, either only in the session or only during the page access?
– Maicon Carraro
You want to keep the items on
combobox
only when your item addition form is closed or you want the items to remain when the entire application is closed?– gato