An alternative approach could be to generate the array dynamically, the framework is already storing references to all of the controls, both static and dynamic, so you can just recurse through the ControlCollections pulling out all of the ones of the required type. private void searchControlTree(ControlCollection colControls , ArrayList allCtls, System.Type ctlType) { foreach (Control c in colControls ) { if ( c.GetType() == ctlType) allCtls.Add(c) ; if (c.Controls.Count > 0 ) searchControlTree(c.Controls, allCtls, ctlType ) ; } } public ArrayList findControlByType( System.Type ctlType) { ArrayList allCtls = new ArrayList(); searchControlTree(this.Controls, allCtls, ctlType) ; return allCtls ; } ArrayList a = findControlByType( typeof(TextBox)) ;
If you need a real array at the end the ArrayList has a ToArray() method. If you combine this approach to finding the controls together with the control Name
or Tag
properties you can filter out whatever controls you want. Hope this is usefull Jackson
User 1180270
Posts
-
Indexed textboxes -
@-quoted stringsI think your right. Thanks Jackson
-
@-quoted stringsSenthil, Yes - this does indeed solve the problems for newlines, and is the route I had started down. However the issue with this approach is the I have to code up a method that knows about all of the escape codes and transforms them. I was hoping to find a method that didn't require that I capture this information in code. However I can't think of anything better :) and it should be possible to write a big regexp that covers of the escape sequences I want to allow. Thanks for the help Jackson
-
@-quoted stringsWell - I've added the following two lines to the app:
System.Console.WriteLine(format); System.Console.WriteLine("test\nstring");
And this produces the following in the Output Window:The user says\n{0} test string
Just to confuse things further before I display the final string from the StringBuilder I looked at the value in the string and the debugger shows the following:msg="Test Dynamic Form\nLess than 20 users impacted\nNo you can't\nNO VALUE SELECTEDThe user says\\nTest"
The debugger does not show the @ for a @-quoted string this time and the final \n has been escaped! It isn't escaped when its in the variable format - just to be sure i replaced all occurances of \ with ! and printed out the result. So - still confused here:-D -
@-quoted stringsI've got a slight problem with @-quoted strings in C#. I'm reading some XML formatted data using a XmlTextReader. At some point in this process I get a chunk of text that contains some escape sequences. I want to use this as the format part in an StringBuilder.AppendFormat() method.
StringBuilder sb = new StringBuilder() ; string format = myXmlTextReader.Value ; sb.AppendFormat(format, ...) ;
However the value in format is @-quoted. If I look in the debugger it shows the following:format = @"The user says\n{0}"
I just can't work out how to un @-quote the string in code. :confused: I want the newline in the string not the \n. There must be a simple way to do this but I just can't find it! TIA Jackson