internal override void ViewChangedSelectedRecord(SIL.FieldWorks.Common.FwUtils.FwObjectSelectionEventArgs e, SIL.FieldWorks.Common.COMInterfaces.IVwSelection sel) { base.ViewChangedSelectedRecord(e, sel); UsedToSyncRelatedClerk = false; if (sel == null) return; // See if we can make an appropriate Subitem selection. var clevels = sel.CLevels(false); if (clevels < 2) return; // paranoia. // The object we get with level = clevels - 1 is the root of the whole view, which is of no interest. // The one with clevels - 2 is one of the objects in the top level of the list. // We get that initially, along with the tag that determines whether we can drill deeper. // Starting with clevels - 3, if there are that many, we keep getting more levels // as long as there are some and the previous level had the right tag. int hvoObj, tag, ihvo, cpropPrevious; IVwPropertyStore vps; sel.PropInfo(false, clevels - 2, out hvoObj, out tag, out ihvo, out cpropPrevious, out vps); int hvoTarget = hvoObj; for (int index = clevels - 3; index >= 0 && tag == SubitemFlid; index --) { sel.PropInfo(false, index, out hvoTarget, out tag, out ihvo, out cpropPrevious, out vps); } if (hvoTarget != hvoObj) { // we did some useful drilling. Subitem = Cache.ServiceLocator.GetObject(hvoTarget); } else { Subitem = null; // no relevant subitem. } }