I'm primarily interested in Blogs, so I guess I'm fine if this doesn't quite work as expected for Events (I'll just use the regular CategoriesTree control for that).
The fix worked for getting the proper hierarchy. However, i was wondering if we can take it one step further. if you observe the regular behavior of the regular CategoriesTree control, when
ShowRootCategory is set to
FALSE, the rendered TreeView will only show root category when THAT category itself was used in a blog post. If you set
ShowRootCategory to
TRUE, then it will show the root category
NO MATTER WHAT. i think your last modification above basically does what the regular CategoriesTree does when ShowRootCategory = TRUE.
So, now I'm trying to figure out how to get it to work properly when ShowRootCategory = FALSE. I thought I would loop through all of the filtered categories
AFTER they have been all collected, and check each one to make sure it EITHER:
a.) has a parent category in the list (like you were doing already), but only if ShowRootCategory = True,
OR
b.) has its ParentCategoryID set to empty Guid, only if ShowRootCategory = False AND the parent is NOT found in the list. This would make it a first-level node in the TreeView, I'm guessing, making it appear like it doesn't have a parent.
So I started to do this, but I ran into a problem (I commented out the last thing you added, and moved it further down, after the loops):
It seems that it won't let me change the ParentCategoryID because it's probably trying to do this on the actual category that's stored in Sitefinity, and not a copy of it that would be used for the TreeView. Is that right?
I suppose I can go back to using the custom class object (or some other data structure, like DataTable) to capture and store the CategoryName, ID, and CategoryParentID, so that I can manipulate the values BEFORE they get handed off to TreeView.DataSource, but I'm afraid that this is a lot more expensive operation than using native IList<ICategory>. I can give it a try and compare the speed of both approaches, I suppose.
Any thoughts? Am I making sense with what I'm trying to do?