Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
i have a chart of account tree view and i want to sort tree after level one when expand any parent node

What I have tried:

tvChartOfAccounts.Sort
Posted
Comments
BillWoodruff 9-May-18 7:37am    
Precisely define what you mean by "sort:" do you mean re-order the child nodes recursively ? What is the sort based on ? Why aren't the nodes added in sort-order ?
ibrahim maher 9-May-18 8:01am    
thank for reply

I want to sort(ascending order) child nodes after expand any Parent node because i want to sort all tree without root level

note : when the tree build-ed by data table (SQL String) I used an order by Code filed and so the tree appear now sorted by Code not by name but now i want to showing it sorted by name after expand any level (expand Event)

best regrades
BillWoodruff 9-May-18 9:32am    
I've worked with the Win TreeView for years; imho, you are taking on a lot of work when you want to change the positions of child nodes by sorting them. Much better to sort via db query using the same method to create the nodes sorted by name that you use now to create them sorted by code.

But, answer these questions, and I'll see if I can help:

1. is the treeview deeply nested ?

2. are the child nodes of any given node regular in terms of count

3. wouldn't you want to have a way to switch back to sorted by code after sorting by name ?

You may find some code I wrote here useful:

https://www.codeproject.com/Answers/1242930/Treeview-nodes-shown-in-listbox
ibrahim maher 10-May-18 3:36am    
Thanks for reply
answer the three questions :
1- yes the treeview deeply nested
2- yes
3-no
note : I Have use a dataSet object to relate between parent and child to fill the tree by using Account Code Field like :

dsTemp.Relations.Add("TempRepation", dtTemp.Columns[fldMainCode], dtTemp.Columns[fldSubCode])

and so I can't fill tree by Name Field
BillWoodruff 10-May-18 2:04am    
Note: based on your lack of response to the efforts I made to help you here:

https://www.codeproject.com/Answers/1213846/How-to-modify-text-or-caption-property-to-all-obje

I am not motivated to respond with code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900