|
I ended up using a combination of a queue and access counters. Whenever an object is accessed, I call GC.GetTotalMemory() to determine how many objects to de-reference.
Anyway, this thread has nothing to do with Dispose.
|
|
|
|
|
Control[] controlArrays = new Control[3];
controlArray[0] = textbox1;
controlArray[1] = textbox2;
controlArray[2] = textbox3;
for(int i = 0; i < controlArrays.Length; i++)
{
if(controlArray[i] is TextBox)
(TextBox)controlArray[i].Text = "My Array #" + i.ToString();
}
Thanks.
modified on Friday, December 4, 2009 12:13 AM
|
|
|
|
|
You could create an array of type System.Windows.Forms.Control instead of object. After all, if you are only going to keep textboxes inside your array it does not make sense to use an object type. You could even use System.Windows.Forms.TextBoxBase if you really just need to store text boxes.
Since you know your array elements anyway, you could also do something like - Control[] controlArrays = new Control[]{textbox1,textbox2,textbox3};
Looks neater, thats all .
I'm no expert, but I dont see any problems in storing controls inside an array.
|
|
|
|
|
I got an error there, i really meant Control, not object. Thanks.
I asked because I saw an article regarding making Control Arrays in C# but
its longer and a lot more complicated.
|
|
|
|
|
If you are going to put only textboxes in the array, create an array of TextBoxes. That will avoid all that casting.
50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!
|
|
|
|
|
Consider using a List instead of an array, unless you have specific needs that dictate using an Array. The List class will automatically re-size as you add objects, yet you can still iterate and reference by index.
For example:
List<Control> controls = new List<Control>();
controls.Add(textbox1);
controls.Add(textbox2);
controls.Add(textbox3);
controls.Add(textbox99999999999);
for(int i = 0; i < controlArrays.Length; i++)
{
if(controls[i] is TextBox)
(TextBox)controls[i].Text = "Element #" + i.ToString();
}
|
|
|
|
|
Use Arraylist and then filter the Textbox controls from the form controls to get collection of controls.
visit the link for more info : <a href="http://www.dreamincode.net/forums/showtopic45666.htm">http:
modified on Friday, December 4, 2009 5:39 AM
|
|
|
|
|
Use a Generic List. It is much faster, resizes automatically and also avoids runtime type casts.
List<TextBox> textBoxes = new List<TextBox>():
textBoxes.Add(textBox1);
textBoxes.Add(textBox2);
textBoxes.Add(textBox2);
int i =0;
foreach(TextBox textBox in textBoxes) {
textBox.Text = string.Format("My Array {0}", ++i);
}
|
|
|
|
|
Hi,
take a look at the System.ComponentModel.CollectionBase class.
you can write your own ControlCollection and do various operations on Adding to collection..
greetz
|
|
|
|
|
That looks OK, but why would you want to?
|
|
|
|
|
I Have a string
<Parameters>
<UserProfileState>0</UserProfileState>
<Parameter>
<Name>Report_Parameter_0</Name>
<Type>String</Type>
<Nullable>False</Nullable>
<AllowBlank>True</AllowBlank>
<MultiValue>False</MultiValue>
<UsedInQuery>False</UsedInQuery>
<State>MissingValidValue</State>
<Prompt>Report_Parameter_0</Prompt>
<DynamicPrompt>False</DynamicPrompt>
<PromptUser>True</PromptUser> </Parameter>
<Parameter> <Name>Report_Parameter_1</Name>
<Type>String</Type> <Nullable>False</Nullable>
<AllowBlank>True</AllowBlank>
<MultiValue>False</MultiValue>
<UsedInQuery>False</UsedInQuery>
<State>MissingValidValue</State>
<Prompt>Report_Parameter_1</Prompt>
<DynamicPrompt>False</DynamicPrompt>
<PromptUser>True</PromptUser>
</Parameter> </Parameters>
I want to do string manipulation with this and i want to
<Name>Report_Parameter_0</Name>
they are 2 <name>
its not xml ..!
how to do in good method.!
any help is greatly appreciated..!
|
|
|
|
|
Can you use C# regular expressions for this?
|
|
|
|
|
Ty For Your Reply..!
How Can i get the value of
<<Name>Report_Parameter_0</Name>
Report_Parameter_0 for this one..!
|
|
|
|
|
I guess if you could get down to <<Name>Report_Parameter_0</Name> using regular expressions or otherwise, you could then just use a strings substring or indexOf property to parse the parameter.
<name>Report_parameter_o is actually an xml string, so you could even try using XDocument document = XDocument.Parse(xmlString); via Linq.
I have not tried that myself, so please dont screw me if it does not work .
|
|
|
|
|
Abhinav S wrote: so please dont screw me if it does not
LoL
Thanks For Your suggestion i will try..!
|
|
|
|
|
Hi
1. The string you posted is a valid XML. So why can't you load the string into an XML Document and navigate through the Child Nodes?
2. Or Use good old plain string matcing. Find the Start Index of <Name> and </name>. Then get the substring.
3. Use Regular Expressions
|
|
|
|
|
This is xml file. you can use xml object to find the parameters.......
|
|
|
|
|
|
It sure looks like XML to me. I'd use an XmlDocument or a Regular Expression.
|
|
|
|
|
This[^] article may help.
/ravi
|
|
|
|
|
hello how do I break the code of a rectangular matrix to determine the no of columns that don't contain any zero element
|
|
|
|
|
sammathews wrote: using class string
|
|
|
|
|
Sounds like homework to me!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
You have a two-dimensional array of strings? And you want to test the members to see if any are empty?
I'm sure your teacher or textbook already gave you hints on how to do that.
|
|
|
|
|
How do you highlight a treeview node at startup?
I have the node needed from BuildNodeTree() as defaultNode, and the following in frmMain_Load
private void frmMain_Load(object sender, EventArgs e)
{
BuildNodeTree();
treeview.SelectedNode = defaultNode;
}
This doesn't highlight the node. I'm assuming because it hasn't displayed yet.
What are my options?
Thank you.
|
|
|
|