Reputation: 41832
I am beginner in c#. In my project, I populated a xml file inside a TreeView control. If the xml file is large, the TreeView
control is showing the data with scroll bars. Beside this, whenever the user double clicks a node I am showing a panel beside the selected node something like this..
When I scroll the TreeView Control :
My question is how to make the panel
attached to treeView
control so that eventhough the user scrolls the TreeView
control the panel should also move along with the selected node.
Upvotes: 0
Views: 1636
Reputation: 941317
Well, hard to do since TreeView doesn't have a Scroll event. It isn't reliable anyway since nodes can be expanded and collapsed, changing the position and visibility of the node. The backup plan is to use a Timer. This worked well:
private void timer1_Tick(object sender, EventArgs e) {
var node = treeView1.SelectedNode;
if (node == null || !node.IsVisible) panel1.Visible = false;
else {
panel1.Visible = true;
var nodepos = treeView1.PointToScreen(node.Bounds.Location);
var panelpos = panel1.Parent.PointToClient(nodepos);
panel1.Top = panelpos.Y;
}
}
Upvotes: 2