私はVBの人ではありませんが、C#では次のようにします。
いくつかのWin32ネイティブ関数:
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int GetScrollPos(IntPtr hWnd, int nBar);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern int SetScrollPos(IntPtr hWnd, int nBar, int nPos, bool bRedraw);
private const int SB_HORZ = 0x0;
private const int SB_VERT = 0x1;
現在のスクロール位置のポイントを返すメソッド:
private Point GetTreeViewScrollPos(TreeView treeView)
{
return new Point(
GetScrollPos(treeView.Handle, SB_HORZ),
GetScrollPos(treeView.Handle, SB_VERT));
}
スクロール位置を設定する方法:
private void SetTreeViewScrollPos(TreeView treeView, Point scrollPosition)
{
SetScrollPos(treeView.Handle, SB_HORZ, scrollPosition.X, true);
SetScrollPos(treeView.Handle, SB_VERT, scrollPosition.Y, true);
}
次に、ツリーを更新するときに、次の手順を実行します。
BeginUpdate();
Point ScrollPos = GetTreeViewScrollPos(treeMain);
// write your update code here
SetTreeViewScrollPos(treeMain, ScrollPos);
EndUpdate();