Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / September 2005

Tip: Looking for answers? Try searching our database.

IVsUIHierarchyWindow::ExpandItem returns E_FAIL

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Notre Poubelle - 13 Sep 2005 22:43 GMT
Hello,

I've built my own hierarchy which I'm displaying in custom toolwindow that
uses the UIHierarchyWindow control.  I would like to select an item so I'm
using the following (managed) code:

object docView
ErrorHandler.ThrowOnFailure((m_windowFrame).GetProperty((int)__VSFPROPID.VSFPROPID_DocView, out docView));
IVsUIHierarchyWindow hierarchyWindow = (IVsUIHierarchyWindow)docView;
ErrorHandler.ThrowOnFailure(hierarchyWindow.ExpandItem(m_altUIHierarchy,
(uint) altHierItemId, EXPANDFLAGS.EXPF_SelectItem));

The call to ExpandItem throws an exception which translates to E_FAIL.  The
hierarchy window is hosting a single hierarchy (m_altUIHierarchy) and
altHierItemId is the itemId of a leaf node item in the hierarchy.  Why would
ExpandItem return an E_FAIL code?  Note that if I select the root node
(rather than a leaf node), no exception is thrown.

Thanks,
Notre
"Ed Dore [MSFT]" - 14 Sep 2005 01:47 GMT
Hi Notre,

I've been working on a sample package this afternoon, that implements a
VsUIHierarchyWindow toolwindow myself.

Does this leaf node, have children? Can you determine what properties the
shell is asking for when you call ExpandItem? (hint, add a Trace call in
your IVsHierarchy.GetProperty implementation. I'm guessing that this is
probably where the E_FAIL is coming from.

I'll try to wire up a command in my sample package, and see if the same
thing happens to me later this evening. Will post back tomorrow with the
results.

Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 14 Sep 2005 17:44 GMT
Hi Ed,

No, the  leaf node does not have any children.  Is this valid to call
ExpandItem on?  My goal is to select a node in the hierarchy, not really
expand it.  It looks like IVsUIHiearchyWindow::ExpandItem method can use the
EXPF_SelectItem flag to select an item, and that is what I'm doing.

I will try the trace trick you suggested (never thought of that!) and post
back my results.

Notre
"Ed Dore [MSFT]" - 14 Sep 2005 18:46 GMT
Hi Notre,

Calling IVsUIHierarchyWindow.ExpandItem(myHierarchy, itemid,
EXPANDFLAGS.EXPF_SelectItem) worked in my demo package.

I noticed a lot of GetProperty calls when calling ExpandItem. I don't have
support for most of the VSHPROPID properties as of yet. But I suspect
VSHPROPID_ParentHierarchy might be a key property here, as I haven't
actually implemented any of the others (like BrowseObject and
SelContainer). For VSHPROPID_ParentHierarchy, I return my IVsHierarchy for
all items "except" the VSITEMID_ROOT item. For VSITEMID_ROOT I actually
pass back a null, and return DISP_E_MEMBERNOTFOUND from the GetProperty
call.

I'd be more than happy to pass along a copy of my package for comparison.
Just fire me off an email (remove the ".online" from the address), and I'll
zip it up and pass it along. It's just a quick start to a package I'm
hoping to eventually post to gotdotnet, once I implement a couple hierarchy
implementations to plug into the toolwindow. This was just my second stab
at implementing a tiny (non-project based) hierarchy. Currently, it's built
against Whidbey Aug CTP, and Sept. VS SDK.

Sincerely,
Ed Dore [MSFT]

This post is "AS IS" with no warranties, and confers no rights.
Notre Poubelle - 14 Sep 2005 23:59 GMT
Hi Ed,

I tried putting some tracing code in my implementation of GetProperty.  
Here's my tracing code (largely borrowed from HierarchyNode.cs):

           if (propId != LastTracedProperty)
           {
               string trailer = (result == null) ? "null" :
result.ToString();
               System.Diagnostics.Trace.WriteLine("Property change: " +
this.hierarchyId + "," + propId.ToString() + " = " + trailer);
               LastTracedProperty = propId; // some basic filtering here...
           }

If I select a leaf node as input to ExpandItem, then as a direct result I
get the following trace output from my GetProperty implementation:

Property change: 4,-1000 = 2
Property change: 4294967294,-2032 = null
Property change: 4,-1000 = 2
Property change: 4294967294,-2032 = null
Property change: 4,-1000 = 2
Property change: 4294967294,-2032 = null

According to VSShell.idl, the property -1000 is defined as this:
VSHPROPID_Parent                  = -1000, // I4   itemid of Parent node
(ITEMID_NIL if no parent)

and the -2032 property is defined as:
VSHPROPID_ParentHierarchy         = -2032, // UNK  IVsHierarchy that owns
this hierarchy.  Hold as UNADDREF'ed ptr in SetProperty.

As you can see from the trace output, the query for VSHPROPID_Parent for my
child node (item id == 4) returns 2, which I believe is correct.  The query
for the VSHPROPID_ParentHierarchy occurs only on the root node and my
implementation is to return null.

If instead of selecting a leaf node, I instead select the root node to be
used as input to the ExpandItem method, I get an S_OK  return value and my
tracing code returns absolutely nothing!

I also changed my implementation of GetProperty to handle the
VSHPROPID_ParentHierarchy property as you suggested.  This didn't seem to
help, as it does not appear to be queried for the leaf node, at least based
on my rudimentary tracing code in GetProperty.

Any suggestions?

Notre
"Ed Dore [MSFT]" - 15 Sep 2005 00:32 GMT
Hi Notre,

It might be your handling of the VSHPROPID_Parent. If the itemid passed to
GetProperty is the VSITEMID_ROOT of your hierarchy, you'll want to pass
back a VSITEM_NIL value and return S_OK.

Here's what my GetProperty implementation currently looks like. The
hierarchy consists of one root item and two children.

       public int GetProperty(uint itemid, int propid, out object pvar)
       {
           string s = string.Format("GetProperty for itemId ({0}) called
with propid = {1}", itemid.ToString(), propid.ToString());
           Trace.WriteLine(s);

           pvar = null;
           switch (propid)
           {
               case (int)__VSHPROPID.VSHPROPID_CmdUIGuid:
                   pvar = typeof(HierAnarchyPkg).GUID;
                   break;

               case (int)__VSHPROPID.VSHPROPID_Parent:
                   if (itemid == VSConstants.VSITEMID_ROOT)
                       pvar = VSConstants.VSITEMID_NIL;
                   else
                       pvar = VSConstants.VSITEMID_ROOT;
                   break;

               case (int)__VSHPROPID.VSHPROPID_FirstChild:
                   if (itemid == VSConstants.VSITEMID_ROOT)
                       pvar = childItem1._Id;
                   else
                       pvar = VSConstants.VSITEMID_NIL;
                   break;

               case (int)__VSHPROPID.VSHPROPID_NextSibling:
                   if (itemid == childItem1._Id)
                       pvar = childItem2._Id;
                   else
                       pvar = VSConstants.VSITEMID_NIL;
                   break;

               case (int)__VSHPROPID.VSHPROPID_Expandable:
                   if (itemid == VSConstants.VSITEMID_ROOT)
                       pvar = true;
                   else
                       pvar = false;
                   break;

               case (int)__VSHPROPID.VSHPROPID_IconImgList:
               case (int)__VSHPROPID.VSHPROPID_OpenFolderIconHandle:
                   pvar = (int)_imageList.Handle;
                   break;

               case (int)__VSHPROPID.VSHPROPID_IconIndex:
               case (int)__VSHPROPID.VSHPROPID_OpenFolderIconIndex:
                   pvar = GetItem(itemid)._IconIndex;
                   break;

               case (int)__VSHPROPID.VSHPROPID_Caption:
               case (int)__VSHPROPID.VSHPROPID_SaveName:
                   pvar = GetItem(itemid)._Caption;
                   break;

               case (int)__VSHPROPID.VSHPROPID_ShowOnlyItemCaption:
                   pvar = true;
                   break;

               case (int)__VSHPROPID.VSHPROPID_ParentHierarchy:
                   if (itemid == childItem1._Id || itemid ==
childItem2._Id)
                       pvar = this as IVsHierarchy;
                   break;
           }

           if (pvar != null)
               return VSConstants.S_OK;

           return VSConstants.DISP_E_MEMBERNOTFOUND;
       }

If that doesn't help fire me off an email, and I'll zip up the package for
you.

Sincerely,
Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.
Notre Poubelle - 26 Sep 2005 17:12 GMT
The problem turned out to be a case of garbage in, garbage out.  I passed in
a bad Item Id and Ed tracked it down.  Thanks for your help Ed!
Ed Dore [MSFT] - 29 Sep 2005 04:11 GMT
You're more than welcome Notre.

As a follow up to Notre's earlier observation that there were a LOT of
GetProperty calls for VSHPROPID_ParentHierarchy. This was due to Notre
implementing IOleCommandTarget on his hierarchy, whereas I didn't actually
have that in my very simple hierarchy implementation. When IVsUIHierarchy
and IOleCommandTarget are implemented on the same object, you will likely
see a lot more GetProperty calls like this, due to the way the shell does
it's command routing. Bearing in mind this is perfectly legitimate, and
pretty much all of the VS project systems do this. Just wanted to point out
why there was a discrepency between our two implementations.

Cheers,
Ed Dore [MSFT]

This post is 'AS IS' with no warranties, and confers no rights.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.