Click here to Skip to main content
15,041,391 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 3: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?
tyska 8-Nov-12 8:54am
   
binding was done for me when i dropped the textboxes from the datasource(hope you know what i mean). i'm really a beginner and this is my first serious app all by myself so i'm not very confident with programmatical binding but if there's no other way i'll try to do it.
manognya kota 8-Nov-12 8:57am
   
You might have to bind your text box on change of your combo box.
vir1111 8-Nov-12 10:53am
   
i need forumn code

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