我正在使用TreeListView(ObjectListView)并使用DB中的一些项填充它:
class Data
{
public int ID { get; set; }
public string Name { get; set; }
public List<Data> Child;
public Data(int id, string name)
{
ID = id;
Name = name;
Child = new List<Data>();
}
}
如何选择对象(节点),滚动树并将父节点展开(如有必要)?我试过这个:
var node = data.SelectMany(x => GetChildren(x)).Where(x => x.ID == 100).FirstOrDefault();
if (node != null)
{
this.tlv.Select();
this.tlv.SelectObject(node, true);
<???>
}
对于普通的WinForms TreeView,我的代码如下:
treeView1.SelectedNode = findNodes[j];
findNodes[j].EnsureVisible();
WinAPI.SendMessage(treeView1.Handle, WinAPI.WM_HSCROLL, (IntPtr)WinAPI.SB_LEFT, IntPtr.Zero);
答案 0 :(得分:3)
ObjectListView
有一个Reveal()
方法就是这样做的。来自文档:
展开给定模型的所有祖先,并确保它可见。
所以你的代码应该简单:
this.tlv.Reveal(node, true);