I have too many textboxes and comboboxes in wpf form so i just want to know how to reset all the controls at once on a button click
How to reset controls in wpf
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shweta LodhaRank #31 · 39.8K reputationPosted Feb 9, 2016, 12:45 AM EST
Hi Shubha Kumar,
You have to iterate through all the visual elements in your form and then by checking the specific types (for you it is textbox and combobox), you can reset them. Code to get all the visual object is:
public static void EnumVisual(Visual parent, List<Visual> myCollection){
for (int iCount = 0; iCount < VisualTreeHelper.GetChildrenCount(parent); iCount ++)
{
// Get the child at mentioned index value.
Visual childVisualObject = (Visual)VisualTreeHelper.GetChild(parent, iCount);
// Add the child object to the your collection.
myCollection.Add(childVisualObject);
EnumVisual(childVisualObject, myCollection);
}}
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 24, 2019, 6:27 AM EST