private void SelectAndScrollToCurrentRecord() { bool fOldForce = BaseVirtualHandler.ForceBulkLoadIfPossible; // Scroll the display to the given record. (See LT-927 for explanation.) try { BaseVirtualHandler.ForceBulkLoadIfPossible = true; // disable "compute-every-time" // Todo JohnT: move IP to specified record. (The following code does this, // but makes a range selection of the entire object instead of an IP.) // Also override HandleSelChange to update current record. RecordClerk clerk = Clerk; IVwRootBox rootb = (m_mainView as IVwRootSite).RootBox; if (rootb != null) { int idx = clerk.CurrentIndex; if (idx < 0) { return; } // Review JohnT: is there a better way to obtain the needed rgvsli[]? IVwSelection sel = rootb.Selection; if (sel == null) { sel = rootb.MakeSimpleSel(true, false, false, true); } int cvsli = sel.CLevels(false) - 1; // Out variables for AllTextSelInfo. int ihvoRoot; int tagTextProp; int cpropPrevious; int ichAnchor; int ichEnd; int ws; bool fAssocPrev; int ihvoEnd; ITsTextProps ttpBogus; SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli, out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd, out ws, out fAssocPrev, out ihvoEnd, out ttpBogus); rgvsli[cvsli - 1].ihvo = idx; sel = rootb.MakeTextSelInObj(ihvoRoot, cvsli, rgvsli, 0, null, false, false, false, true, true); if (sel == null) { // If the current selection is in a property that the new selection // lacks, making the selection can fail. If that happens, try again at // a higher level. See LT-6011. int cvsliNew = cvsli - 1; while (sel == null && cvsliNew > 0) { // Shift the SelLevInfo values down one place in the array, getting // rid of the first one. for (int i = 1; i <= cvsliNew; ++i) { rgvsli[i - 1] = rgvsli[i]; } sel = rootb.MakeTextSelInObj(ihvoRoot, cvsliNew, rgvsli, 0, null, false, false, false, true, true); --cvsliNew; } } // TODO: implement and use kssoCenter. (m_mainView as IVwRootSite).ScrollSelectionIntoView(sel, VwScrollSelOpts.kssoDefault); // It's a pity this next step is needed! rootb.Activate(VwSelectionState.vssEnabled); } } catch { // not much we can do to handle errors, but don't let the program die just // because the display hasn't yet been laid out, so selections can't fully be // created and displayed. } finally { BaseVirtualHandler.ForceBulkLoadIfPossible = fOldForce; // reenable "compute-every-time" } }