This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
// accesses a control by ID (i.e. a checkbox/button/textbox etc) | |
private static Control FindControlIterative(Control root, string id) | |
{ | |
Control ctl = root; | |
LinkedList<Control> ctls = new LinkedList<Control>(); | |
while (ctl != null) | |
{ | |
if (ctl.ID == id) | |
return ctl; | |
foreach (Control child in ctl.Controls) | |
{ | |
if (child.ID == id) | |
return child; | |
if (child.HasControls()) | |
ctls.AddLast(child); | |
} | |
ctl = ctls.First.Value; | |
ctls.Remove(ctl); | |
} | |
return null; | |
} | |
// To call the method, use something like: | |
public MainMethod() | |
{ | |
// get a textbox that has the ID "address" | |
TextBox txt = FindControlIterative(control, "address") as TextBox; | |
// change the text of that textbox | |
txt.Text = "some text"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment