Hi
I have a question.
There is a treeview control with few nodes in it.
When ever i select a node1 and click a button ADD, the node should get saved . It can be in a arraylist or string builder. After that i select one more node2 and it should also be saved . The first node1 and second node2 must be separated by ','(Comma). So my final string should be node1,node2,node3. This string must be saved in DB.
My question is How should i collect these strings from treecontrol and save it in DB.
I dont have any idea about arraylist or string builder. How should i do this.
Please help me
Bechir BejaouiPosted Dec 17, 2008, 5:10 PM
OK, let's start with the string builder, you ask me why do I use string builder as string can do the mission, I respond it does the mission but with less performance as each time you modify the string it will be destroyed and rebuit from the beginning at the RAM level at the contrast of the string builder that remains as one persisted object each time you add a string it is added to a sort of stack, so the sring builder is not destroyed each time we need to do update at the contrast of the string
this is a code that I keveraged for you to just get started:
StringBuilder myBuilder = new StringBuilder();
myBuilder.Append("Hi ");
myBuilder.Append("I'm ");
myBuilder.Append("Bechir ");
myBuilder.Append("Bejaoui ");
string Statement = myBuilder.ToString();
myBuilder.Replace("Bechir ","sairam ");
myBuilder.Replace("Bejaoui ", "About my last name? I can't give it, sorry ");
string NewStamtement = myBuilder.ToString();
MessageBox.Show(NewStamtement);
myBuilder.Remove(14, 42);
string NewestStatment = myBuilder.ToString();
MessageBox.Show(Statement);
MessageBox.Show(NewestStatment);
What has the stringbuilder over the ArrayList is that it can replace old strings by new ones and can get it content if you use the ToString() method
For more details about string builder and how it works, please refer
http://msdn.microsoft.com/en-us/library/system.text.stringbuilder(VS.80).aspx
Now, the Arraylist role, It is good espacially for stocking object it plays the role of an array but the main difference is that it need not to set a length at the begenning like an array in addition it can stock different objects from different types meanwhile the array can stock only one type of object at once, here is a code of how to use it
StringBuilder myBuilder = new StringBuilder();
myBuilder.Append("Hi ");
myBuilder.Append("I'm ");
myBuilder.Append("Bechir ");
myBuilder.Append("Bejaoui ");
string Statement = myBuilder.ToString();
myBuilder.Replace("Bechir ","sairam ");
myBuilder.Replace("Bejaoui ", "About my last name? I can't give it, sorry ");
string NewStamtement = myBuilder.ToString();
MessageBox.Show(NewStamtement);
myBuilder.Remove(14, 42);
string NewestStatment = myBuilder.ToString();
MessageBox.Show(Statement);
MessageBox.Show(NewestStatment);
What can do the ArrayList over the StringBuilder is that it can sort inverse sort remove objects at given indexes
For know in advantage how to deal with an ArrayList please refer
http://msdn.microsoft.com/en-us/library/system.collections.arraylist.aspx
sairamPosted Dec 16, 2008, 7:23 PM
Bechir BejaouiPosted Dec 16, 2008, 7:22 PM