Click here to Skip to main content
15,843,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a combobox and bound textboxes that show details of a chosen item.
When I choose items, everything works fine. on selected index = 0, new form is opened and if i cancel it, i need the selected index to be set to -1.

So when i do that, the data in the text boxes is left from previously selected item(before index 0 was selected). so i clear the text boxes (textboxes.text = "").

then, when I choose an item from the combobox it selects it but textboxes are empty. If I do another selection then it shows values, so it seems like the clearing txtboxes has something to do with that.

how can I achieve the clearing of the txtboxes after setting index to -1 without preventing no show of data after next selection?

[Edit]
Here is some code:
C#
private void clientsComboBoxEx_SelectedIndexChanged(object sender, EventArgs e)
{
    if (clientsComboBoxEx.SelectedIndex == -1)
    {
        editClientButton.Enabled = false;
        foreach (TextBox tb in groupBox1.Controls.OfType())
        {
            if (tb.Text != "")
            {
                tb.ResetText();
            }
        }
    }
    if (clientsComboBoxEx.SelectedIndex == 0)
    {
        editClientButton.Enabled = false;
        cb = clientsComboBoxEx;
        NewClient newclientform = new NewClient(cb);
        newclientform.ShowDialog();
        clientsComboBoxEx.SelectedIndex = -1;
    }
    if (clientsComboBoxEx.SelectedIndex >0)
    {
        editClientButton.Enabled = true;
    }
}

[/Edit]
Posted
Updated 8-Nov-12 4:33am
v6
Comments
jim lahey 8-Nov-12 8:31am    
You need to share your code for this one.
tyska 8-Nov-12 8:49am    
some code in the edited question
lukeer 8-Nov-12 9:36am    
There is a link called "Improve question" right below your question. Use that to provide such additional information. Then, a tiny comment about your question being updated suffices and the code is much easier to read.
tyska 8-Nov-12 9:45am    
sorry, i'll do that next time
manognya kota 8-Nov-12 8:34am    
Hi,

Are you binding the text box on change of combobox?

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