Click here to Skip to main content
15,936,758 members
Please Sign up or sign in to vote.
4.20/5 (5 votes)
See more:
I have a listbox and mulitiple textboxes on my form.When listbox item is selected i am able to retrieve data from database to texboxes But when new item is inserted in listbox i am using following function to clear all textboxs ...

C#
private void ClearTextBoxes(Control.ControlCollection cc)
       {
           foreach (Control ctrl in cc)
           {
               TextBox tb = ctrl as TextBox;
               if (tb != null)
                   tb.Clear();
               else
                   ClearTextBoxes(ctrl.Controls);
           }
       }
What i want is to get selecteditem name(which is not stored in database yet) into a textbox but because of this function that textbox appearing clear..
Posted
Updated 30-Dec-13 21:48pm
v2
Comments
Sergey Alexandrovich Kryukov 31-Dec-13 0:49am    
You almost got it. One little effort; and you will get it. :-)
—SA
uditCsharp 31-Dec-13 1:09am    
Got it :)
Sergey Alexandrovich Kryukov 31-Dec-13 1:23am    
I knew you would.
Happy New Year!
—SA
uditCsharp 31-Dec-13 3:47am    
Thank You...Wish you the same :)
ZurdoDev 31-Dec-13 12:00pm    
Please post your solution so that this question no longer shows in the Unanswered section.

1 solution

C#
private void ClearTextBoxes(Control.ControlCollection cc)
{
foreach (Control ctrl in cc)
{
TextBox tb = ctrl as TextBox;
if (tb != null)
{
tb.Clear();
textBox1.Text=ListBox1.SelectedItem.ToString();
}
else
ClearTextBoxes(ctrl.Controls);
}
}
 
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