Hi there,

I'm creating an AddIn and I'd like to construct a "TreeView" control whose
nodes match those seen in Solution Explorer. Is there any way to get hold of
these? Thanks very much.

RE: TreeView control and nodes by JJ

JJ
Fri Sep 22 08:13:02 CDT 2006

Hi there. I am not an MVP or anything, but I have been working directly with
this stuff as of late. I had to the get the nodes of the Server Explorer
window, so this should apply to what you are doing. Check out the following
code. First I get the window, just change that to the Solution Explorer
window enum. Then, you can use the UIHeirarchy model to get the nodes. Use
the MSDN to understand more about the UIHeirarchy and UIHeirarchyItem
objects. Once you understand those you are on your way. Good luck.

note that on the GetItem function you can separate your nodes using a \
char. This way you don't have to keep getting the object item off of each
node and drilling down to the level you want, you can just get to your node
directly using this shortcut.

Dim z As EnvDTE.Window =
_applicationObject.Windows.Item(Constants.vsWindowKindServerExplorer)
Dim lssProc As String =
DirectCast(_applicationObject.ActiveDocument.Selection, TextSelection).Text
Dim lsDB As String =my database name ' as it exists in the server
explorer window
Try
Dim x As UIHierarchyItem = CType(z.Object,
EnvDTE.UIHierarchy).GetItem(String.Concat("Data Connections\", lsdb, "\Stored
Procedures\", lssProc))
x.Select(vsUISelectionType.vsUISelectionTypeSelect)
CType(z.Object, EnvDTE.UIHierarchy).DoDefaultAction()

Catch ex As Exception
MessageBox.Show(ex.Message)

End Try


"Michael Chambers" wrote:

> Hi there,
>
> I'm creating an AddIn and I'd like to construct a "TreeView" control whose
> nodes match those seen in Solution Explorer. Is there any way to get hold of
> these? Thanks very much.
>
>
>

Re: TreeView control and nodes by Michael

Michael
Fri Sep 22 10:08:40 CDT 2006

> Hi there. I am not an MVP or anything, but I have been working directly
> with
> this stuff as of late. I had to the get the nodes of the Server Explorer
> window, so this should apply to what you are doing. Check out the
> following
> code. First I get the window, just change that to the Solution Explorer
> window enum. Then, you can use the UIHeirarchy model to get the nodes.
> Use
> the MSDN to understand more about the UIHeirarchy and UIHeirarchyItem
> objects. Once you understand those you are on your way. Good luck.
>
> note that on the GetItem function you can separate your nodes using a \
> char. This way you don't have to keep getting the object item off of each
> node and drilling down to the level you want, you can just get to your
> node
> directly using this shortcut.
>
> Dim z As EnvDTE.Window =
> _applicationObject.Windows.Item(Constants.vsWindowKindServerExplorer)
> Dim lssProc As String =
> DirectCast(_applicationObject.ActiveDocument.Selection,
> TextSelection).Text
> Dim lsDB As String =my database name ' as it exists in the server
> explorer window
> Try
> Dim x As UIHierarchyItem = CType(z.Object,
> EnvDTE.UIHierarchy).GetItem(String.Concat("Data Connections\", lsdb,
> "\Stored
> Procedures\", lssProc))
> x.Select(vsUISelectionType.vsUISelectionTypeSelect)
> CType(z.Object, EnvDTE.UIHierarchy).DoDefaultAction()
>
> Catch ex As Exception
> MessageBox.Show(ex.Message)
>
> End Try

Thanks very much. It looks like this is the right approach so I'll
definitely be looking at it (greatly appreciated!)