Microsoft Developer Network >
Forenhomepage
>
Visual Studio Extensibility
>
VSPackage: How to create a custom virtual node like References node
VSPackage: How to create a custom virtual node like References node
- Hello,
I have a C# flavored project and I want to add some custom nodes to my project where the only options when you right click on them is to add or remove a custom project item that I have already created, so I want it to be like the References node in that it cannot be deleted renamed and it only has 2 context menu options. Any idea or links on how to do something like this would be greatly appreciated.
Thanks
Kenny
Alle Antworten
- This is actually easier than you would think (and I have bunches of custom containers and node types)...
a) Create a container class (like a folder) which inherits from HierarchyNode.
b) Create an item class (like a file) which also inherits from HierarchyNode.
To make it impossible to rename from explorer, override the "SetEditLabel" method and throw NotImplementedException (yes, it's a rather silly technique, but that's the only thing that works). I also override "CanDeleteItem" and return false.
For the container class - override the GetProperty() method and return true for "VSHPROPID_Expandable".
For the item class - don't return true for the ...Expandable (of course).
Take a look at the FileNode and FolderNode classes in the MPF ProjectBase and you'll see how easy this ends up being.
Hope this helps,
Reed SHilts- Als Antwort vorgeschlagenReed Shilts Donnerstag, 25. Juni 2009 23:19
- Thanks for the repsonse but we are not using MPF so we cannot use the HierachyNode class as it uses ProjectNode. Is there any way to do this sort of thing using a Flavored C# project?ThanksKenny
Hi Kenny,
Based on my understanding, you can use Project Template to add a new ProjectNode as Reference Node in treeview. You can export a C# project template by File>Export Template... and then customize your project template, please refer to following code snippet about how to add a new folder note(named NewFolder1) in project template:
For more information, please see : Create Reusable Project And Item Templates For Your Development Team.<TemplateContent> <Project TargetFileName="ConsoleApplication.csproj" File="ConsoleApplication.csproj" ReplaceParameters="true"> <Folder Name="NewFolder1" TargetFolderName="NewFolder1" /> <ProjectItem ReplaceParameters="true" TargetFileName="Program.cs">Program.cs</ProjectItem> <Folder Name="Properties" TargetFolderName="Properties"> <ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem> </Folder> </Project> </TemplateContent>
If I misunderstood you, or you have any questions, please let me know.
Best Regards,
Nancy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Hi Nancy,Thanks for the response, but I think you misunderstood me. I need to create a custom folder in which all the user can do is add or remove a custom project item I have created. I want it to be sort of like the References folder, except you can add my custom project items instead of references. Does that make senese? If you have any questions for me please let me know.ThanksKenny

