|
Thanks alot for the reply .You are correct i am relying on navigating on view but i am using windows forms application and i cant use wpf and other environments thats my problem.
|
|
|
|
|
I wasn't suggesting that you change platforms. What I was suggesting is that you could use a pattern such as MVC, and leverage data binding to trigger the update.
|
|
|
|
|
Ok i am new to c sharp i dint used databinding concept. but i will try out databinding to trigger the update .thank you
|
|
|
|
|
It would be good to know if you are using WinForms, WPF, or ? here.
In this case we don't much about the structure of your TreeView: can it have multiple levels of nesting ?
If it can have multiple levels of nesting, and a "child node" three levels deep has its CheckBox checked, then you tell us that all that node's "sibling nodes," and its "parent node" are to have their CheckBoxes checked: but ... then does the parent of the parent node also get all its child nodes, and itself checked ?
Or, is the (as I would assume) "checking" only of the immediate sibling nodes, and the parent.
What happens if the user then unchecks one of the sibling nodes: does that then uncheck all the other sibling nodes ... and the parent ? If the parent node is unchecked: all the sibling nodes are then unchecked ?
Assuming you allow unchecking in the first TreeView: you then need to alter the second TreeView ? ... I'd guess: "yes."
In any case, you can populate a new TreeView by recursively parsing the existing TreeView and creating new Nodes that match those that are checked in the second TreeView, with the same parent/child relationships.
Is recursive parsing of a TreeView something you know how to do now, or can we help with you that ?
And, if your TreeView is only two levels "deep:" a set of root nodes, and each root node having a set of child nodes: then this becomes very easy.
So, some more information about the structure of your TreeView would be helpful.
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Hi BILL, THANKS ALOT for the reply !!
I am using windows forms application.It can have multiple levels of nesting.
If a node at 3 levels deep is checked only its parent and grand parent are to be checked but not it siblings.
If the user unchecks the a node it has no effect on its siblings but if its parent has no other childs except it then that parent also should be unchecked.
If the parent is unchecked all its childs should be uncheked.
If a node in the first treeview is unchecked it should reflect immeditely in the second treeeview.
Can you help in recursive parsing of treeview you are saying or with any other solution.
|
|
|
|
|
Well, we are making progress in defining the actual structure of your TreeView ... and that's good
This reply raises these questions, for me:
0. is any node in the TreeView ever more than 3 levels deep: in other words: is the level of "nesting" arbitrary ? In other words: is there any regular structure to all nodes that we can assume: for example: they are all 3 levels "deep" ?
1. in the case of one node, which is the only child of its parent: you say the parent should also be unchecked: what about if that parent node is also the "only child" of its parent node: does its "grandfather" then get unchecked ?
a. what if the grandparent node of the only child of the parent node that is unchecked has many other child nodes ... "uncle nodes" ? ... what happens to them: do they get left alone, or unchecked, also ?
2. if a parent node is unchecked: and that parent node has many levels of nested nodes "under it:" do they all get unchecked ... or only the "grandchildren" of that node get unchecked: this would be "symmetric" with the way you now handle unchecking an only child of a node, then its parent, and then its grandparent.
2. is it ever the case that:
a. new nodes are added at run-time ?
b. existing nodes are deleted at run-time ?
To get you started with recursive parsing: put a TreeView on a Form:
0. in the Form Load EventHandler set the 'Expanded property of the TreeView to 'true.
1. edit the Nodes collection at Design-Time, and add a whole bunch of them, nested to various depths
2. set the TreeView 'CheckBoxes property to 'True:
3. put a button on the Form with its Click EventHandler set like so:
private void button1_Click(object sender, EventArgs e)
{
treeView1.ExpandAll();
RecursiveParseTree(treeView1.Nodes, 0);
} 4. And then define the recursive parser:
private void RecursiveParseTree(TreeNodeCollection nodeCollection, int level)
{
foreach (TreeNode theNode in nodeCollection)
{
Console.WriteLine
(
"Node Name: = {0},
Node Level = {1},
Node Checked = {2}",
theNode.Text,
level,
theNode.Checked
);
if (theNode.Nodes.Count > 0)
{
RecursiveParseTree(theNode.Nodes, level++);
}
}
} 5. At run-time check a bunch of nodes at various "depths," and examine the output of running this code in VS's Output Window when you exit the Application.
Discussion: the interesting part is going to be where you get to all the business related to unchecking only-child nodes, and grandparent nodes !
best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
modified 3-Jan-12 5:25am.
|
|
|
|
|
i will answer your questions and i will give the code i wrote for checking subchilds so that it will be more clear for you.
0.Actually nodes in my treeview or folders and its subfolders are childs and sub subfolders are grand childs.when a user gives the folder by folderbrowser dialog i am capturing its path and extracting all its folder hierarchy and showing it in the treeview. so tree can be of any depth.
1.in the case of one node, which is the only child of its parent: you say the parent should also be unchecked: what about if that parent node is also the "only child" of its parent node: does its "grandfather" then get unchecked ?
-yes
a. what if the grandparent node of the only child of the parent node that is unchecked has many other child nodes ... "uncle nodes" ? ... what happens to them: do they get left alone, or unchecked, also ?
- uncle nodes state remains the same, only its parent node (if it is only child for it) is unchecked if it is unchecked.if it is checked obviously its parent node should be checked wether it has other childs or not.
2.if a parent node is unchecked: and that parent node has many levels of nested nodes "under it:" do they all get unchecked ... or only the "grandchildren" of that node get unchecked
-all the nodes shoould be unchecked
2.a. new nodes are added at run-time ? not added but checked or unchecked
b. existing nodes are deleted at run-time ?no not deleted but checked or unchecked.
hope this code will clarify your doubts :
private void Load_treeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
TreeNode parent_node = e.Node;
bool is_checked = parent_node.Checked;
for (int i = 0; i <= e.Node.Nodes.Count - 1; i++)
{
SetSubtreeChecked(parent_node.Nodes[i], is_checked);
}
bool blnUncheck = false;
if ((e.Node.Parent != null))
{
foreach (TreeNode child in e.Node.Parent.Nodes)
{
if (child.Checked == true)
{
blnUncheck = true;
}
}
if (blnUncheck == false)
{
e.Node.Parent.Checked = false;
}
else
{
e.Node.Parent.Checked = true;
}
}
}
private void SetSubtreeChecked(TreeNode parent_node, bool is_checked)
{
parent_node.Checked = is_checked;
for (int i = 0; i <= parent_node.Nodes.Count - 1; i++)
{
SetSubtreeChecked(parent_node.Nodes[i], is_checked);
}
}
the recursive parsing code u gave looks solves the problem i will try that.Thank you
JANARDHAN
|
|
|
|
|
thanks alot Bill
it solved the problem
can i call this RecursiveParseTree() in any of the events of the treeview1 or 2 so that i need not click the button??
JANARDHAN
|
|
|
|
|
JANARDHAN GURRAM wrote: can i call this RecursiveParseTree() in any of the events of the treeview1 or 2 so that i need not click the button?? Yes, you can call it from anywhere, and you can recurse on the whole TreeView, or on any Node in any TreeView.
Whether you'd really want to have a different recursive parser for the second TreeView compared to the first one: well, that's a design problem you'll need to figure out depending on the difference in the way you alter/edit/use the two TreeViews.
Actually, even if you called it on a Node that had no child nodes: you'd pass a TreeNodeCollection whose 'Count property was #0 into the recursive procedure, and it would exit without error.
So, if you are using this recursive parsing on Nodes within the TreeView, you might want to "wrap the call" in something like this:
TreeNode targetNode = ????;
if(targetNode.Nodes.Count > 0)
{
RecursiveParseTree(targetNode.Nodes,0);
}
else
{
} p.s. if answers here help you: please vote: if they didn't help you: please vote. imho, feedback strengthens our whole community.
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
Bill your solution is obsolutely correct and it worked for me..but if there are 50 k nodes like in my case for every little change parsing whole treenodecollection is time taking . so what i did i have sent only checked nodes to the recursiveparsetree and there i have added them to string array and deleted from it when modified and used it for 2nd treeview(actually i need to display in table..wat ever it may be).
private void Load_treeView_AfterCheck(object sender, TreeViewEventArgs e)
{
RecursiveParseTree(e.Node, 0);
}
private void RecursiveParseTree(TreeNode thenode, int level)
{
if(thenode.Checked==true)
{
foreach(TreeNode childNode in thenode.Nodes)
if (childNode.Checked == true)
{
_dataArray.Add(new string[] { thenode.Text, childNode.Text });
}
}
if (thenode.Checked == false)
{
foreach (TreeNode childNode in thenode.Nodes)
{
List<string> Key = new List<string> { thenode.Text, childNode.Text };
_dataArray.RemoveAll(item => Enumerable.SequenceEqual(item, Key));
}
}
}
<div class="signature">JANARDHAN</div>
|
|
|
|
|
Glad you are making progress on your solution !
Obviously, you've come up on the issue of performance, and here a few comments I hope you will find useful:
By the way: have you explored all the possible uses in your scenario of TreeNode.Clone() ... which .... from MSDN: "Copies the tree node and the entire subtree rooted at this tree node." ... ?
0. is there any way you can limit the update to some user-initiated update (i.e., make it a batch operation), which of course may mean you'd have to tolerate a mis-match visually between the two TreeViews, assuming both are displayed at the same time.
If you can "get away with that," then I'd disable the second TreeView anytime it was not synchronized, after some change had been made in the primary TreeView, but the user had not initiated an update.
1. however, if it is an absolute requirement that checking any TreeNode results in immediate changes in the second TreeView: then there are several ideas to explore:
a. since you can get an Event for any TreeNode CheckState changed: and having access to the changed Node also gives you access to its Parent property: does that give you enough information to do a partial update ?
b. whether the FullPath property of a TreeNode could be useful here ? I doubt it, since the WinForms TV gives you no useful methods to use that FullPath to directly get at TreeNodes (by, for example, using only part of the FullPath returned string).
2. view virtualization (showing only what you need to show as updated): I think there may be an example on here on CP of a TreeView supporting "virtual screen update" which means changes are made as they are required to be displayed: while I doubt that's relevant here, at least you might check it out ... for ideas.
3. flatlist: the third-party commercial TreeView I use (Lidor Systems IntegralUI TreeView) maintains a flattened list of all Nodes in depth-first order, which makes operations like the kind of updates you are looking at very much easier: and many other features including "virtualization of view." The WinForms TreeView, by comparison, is a "toy." Yes, that's a recommendation ... and no I don't work for Lidor.
a. on StackOverFlow you'll some good examples of how to create a flattened TreeView List of Nodes, based on ideas of Eric Lippert influenced by ideas of Wes Dyer: the method uses a stack to avoid the high performance/memory costs of true recursion. Check out this thread I started on SO a long time ago: [^].
4. finally, if immediate synchronization of both views here is the goal: re-consider Luc Patyn's suggestion to use your own tree data structure, and map it as needed to "views."
good luck, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle
|
|
|
|
|
i called it in after check event of treeview1 it worked with out need for button.
thanks alot BILL
JANARDHAN
|
|
|
|
|
Hi all,
I program a Snake game using C#.
I have a problem when I moving the snake.
I have a while loop to made the snake move while it's not dead.
Here is the code:
while (!mainSnake.isDead)
{
mainSnake.makeMove();
PicCanvas.Invalidate();
Thread.Sleep(500);
}
The problem is that I don't see the moves of the snake. I just see the "Game Over" mesagebox when the snake "hit the wall".
I want to see any move of the snake (with 500 millisecond delay between any move).
Any ideas?
Thanks ahead.
|
|
|
|
|
I guess the code shown sits in some event handler, i.e. it is executing on the main thread and blocking everything else, until it terminates due to the snake dying. This is what you should do:
- get rid of Thread.Sleep(), it should not be used inside event handlers.
- use a timer instead; for actions that mainly influence the GUI, a System.Windows.Forms.Timer is the right choice.
- put one iteration of your loop inside the timer's tick handler.
|
|
|
|
|
Thank you the timer really worked!
|
|
|
|
|
hi
in my C# program i have export to csv file.
how to preserve zero bebore number in csv file that opens on excell
for example:
i see in my program: 00012345
and if i open on excell i see 12345
thanks in advance
|
|
|
|
|
Add an apostrophe (') before the number and excel will treat it as a text column and display the leading zeroes.
|
|
|
|
|
This is an Excel formatting issue. You should set the cell format for the field in question to display a fixed number of digits for any numeric values.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
AFAIK, csv files do not support formatting.
|
|
|
|
|
I did not say that they did.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
I want convert word doc or word file to image such as tif
|
|
|
|
|
Why would you want to do that? There may be better approaches.
|
|
|
|
|
hey guys i need help plz
i want when i press enter in cell cursor go down to the the cell in same column but when i press tab go to next cell in the same row how ?
|
|
|
|
|
I have just tried this and added a new datagridview to a windows form, and what you want is the default behaviour.
What appears to be the problem that it is not doing this?
|
|
|
|
|
Hi ,
I have a webservice FindStates()which return XML of all the states.
My webservice returns data in a dataset.
1) How to fetch the data from this webservice and put the same data in my database table.
Note: I have the same table structure.
Thanks,
Sandy
|
|
|
|