|
Why are you even bothering? The TreeView already stores the hierarchy of TreeNodes and you can easily get the count at any level using TreeView.Nodes.Count or TreeNode.Nodes.Count . This can even be done recursively very quickly.
What you're doing is not only unnecessary but very error prone as you've already experienced. Don't bother; the TreeView already maintains the node count so use it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok thanx but how do I get the modified TreeView (ie. after deletion of the new nodes..) into a 2D array like I want ?
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
I have written as function to copy the node values (count) depending on the values the tree gives :
private void CopyArr2()
{
p = ruletree.Nodes.Count;
p--;
for(int i=1; i<=p;i++)
{
TreeNode currnode = ruletree.Nodes[i];
if(currnode != null)
{
if(currnode.Nodes.Count > 1)
{
child[i,0] = i;
child[i,1] = currnode.Nodes.Count;
}
else
{
child[i,0] = i;
}
}
}
}
But The resulting array has no modifications even ater I delete a node!!
why?
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Hi C# gurus,
I would like to know where I can get some sample code that shows how to add an additional button in the caption bar of a window? I would like to add a button on the left of the "minimize" button of the caption.
I could do this in MFC, but Windows.Forms is so different
Thanks for the help.
There is no spoon.
|
|
|
|
|
you can drag a button control to the form and then click on the code behind file to see the BtnClick Event handler. Under properties, you can name the button, the text on the button, etc.
However, do you mean adding a button like a COM AddIn, creating a button that way?
|
|
|
|
|
ok I think that he wnts to put a small button beside the _ (minimize) button on top of any window caption bar= ( (new botton) _ (maximise) X)
right?
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
bouli wrote:
I could do this in MFC, but Windows.Forms is so different
Actually, it's not. Underneath it all, Windows Forms makes native API calls and sends or posts, and handles window messages.
The only difference is that not all the APIs, structs, and defs are defined in headers (you can't use headers), so you must P/Invoke the native APIs and define the structs and constants you need.
For example, in your form you want to add a caption for, extend the Form class, override WndProc , and handle the WM_NCPAINT (0x0085) message in a similar fashion as you would with MFC. There's your starting point.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, I should do the same as in MFC, create dynamically a button, paint it in the Non Client area and handle the clicks by trapping the events in the WM_SYSCOMMAND; like for MFC?
There is no spoon.
|
|
|
|
|
Yes; and as I said in my first reply, you need to P/Invoke the necessary APIs and define the necessary structs and constants. Don't forget to actually determine where the minimize button is. Don't always assume you know where it is. Depending on property values, the minimize button may be in a different location. Display settings (size of the caption buttons) may also be different.
There's quite a bit of code in C/C++/MFC available on the 'net that shows you how to do this correctly. Just try googling for it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
there is an excellent implementation in emule of such a button and this implementation also take care if xp styles are enabled or not. I am looking how it is done in emule to do something similar in C#.
thanks for the help
There is no spoon.
|
|
|
|
|
Hello Everybody,
I want to send muliple values(Array values) from one page to other.
I thing query string is not a solution. Session can be helpfull.
But some of my seniors said do not use large number of Session.
Is there any alternating way to avoid both session & query string to send array values.
Please tell me the performance effectt of Query string, Session & alternate one
Thanking You
TusharP
|
|
|
|
|
|
I have to name varibles depending on a count variable. I want to append it to the variable like int "newno" + count = new int();
This gives a syntax error I also tried takin the new value in a string, but that didn't work as well .. It said : A local variable named 'var' is already defined in this scope
when I tried string var = "newno" + count;
and
int var = new int();
HelP!!
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Hi!
What exactly are you trying to do? Are you sure you shouldn't be
using arrays of some sort instead?
An example:
string[] varArray = new string[ sizeGoesHere ];<br />
<br />
for( int i=0; i<varArray.Length; i++ )<br />
{<br />
varArray[i] = "Some Text and counter: "+i;<br />
}
Zerxes
|
|
|
|
|
A little error snuck in..
for( int i=0; i<<varArray.Length; i++ )
Zerxes
|
|
|
|
|
Ack.. That's what you get for trying to post code.
This should be correct
for( int i=0; i<varArray.Length; i++ )
Zerxes
|
|
|
|
|
ok but that's no what I'm tryin to do..
I have a variable static int count = 0; . it is global. I am adding a text box each time I click a button say..
private void btnAddCond_Click(object sender, System.EventArgs e)
{
TextBox "tb" + count = new TextBox();
this.Controls.Add("tb" + count);
}
I hope it explains my plight!!
Help PLZ
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Thought about using the Name property of TextBox class?
Otherwise i don't see a need to give your variable a unique name, because it's gone as soon as you leave the event handler.
private void btnAddCond_Click(object sender, System.EventArgs e)
{
TextBox textbox1 = new TextBox();
this.Controls.Add(textbox1);
}
|
|
|
|
|
I thank you Mr. Stefan Troschütz
Yes It works!! thankx
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
as Mr. Stefan Troschütz has stated for TextBoxes , How do you do it for a simple Integer?
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
What exactly do you want to do with your integers?
I guess storing them in some way like the textboxes
Take a look at the Collections namespace[^] which contains interfaces and classes that define various collections of objects, such as lists, queues, bit arrays, hashtables and dictionaries.
|
|
|
|
|
I want to name anything (integers, long, double, char etc ) which does not have a name property Dynamically.
ex.
static int count = 0;
{
int "var" + count = new int()
}
do you get what I'm tryin' to say??
_____________________________________________________
Yea! I could be wrong...
|
|
|
|
|
Yeah, I get but sorry this
saud_a_k wrote:
int "var" + count = new int() //you get an error on this
isn't possible.
To accomplish a similar effect you could use a SortedList[^] to store your integers whereby the key values are created by the term "var" + count.ToString() .
|
|
|
|
|
You could use an IDictionary implementation like so:
Hashtable vars = new Hashtable();
for (int i=0; i< 10; i++)
vars["newno" + i.ToString()] = i; Once your code is compiled, it cannot be changed. You either need to use Reflection Emit or the CodeDom to generate new source and compile it on the fly (Reflection Emit actually emits an assembly - no compilation necessary but it's far more complex and requires that you know and understand IL).
For your compiled code, you can only maintain the appearance of dynamic variables. This is done through collections, dictionaries, or the ComponentModel (probably not the best idea in your case). Using the approach I described above would probably be the easiest way. To get the int , then, just do int i = (int)vars["newno0"]; .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This is not exactly related to C#, sorry for the same.
The situation is, I have written a class in C#(say root.cs), if some one uses it, I want to compel the user to call 2 public methods (out of say 20 public methods written in root.cs) that he must call inorder to make the correct use of roor.cs
please guide
|
|
|
|