Windows Develop Bookmark and Share   
 index > Windows Forms Designer > programmatically setting the treeview scroll position
 

programmatically setting the treeview scroll position

Hi,

Is there a way to programmatically set the scroll position in a treeview control.

The situation is there are 10 items in mytreeview andthe user can see only first5 nodes/itemsand there is a scrollbar to drag and see the next 5.

There is a text box and search button. If user enters a node name in the text box and hits the search buttonthe node should be selected in the treeview. this is working fine. But if the entered node is in the bottom of the treeview then i want the scrollbar to scroll down and show thenode/item.

please let me know if there to do this.

Thanks

criyaz  Thursday, November 27, 2008 1:05 PM

Hi riyaz c,

Wecan use EnsureVisible method to make the selected item visible. Suppose we make the selected node to be visible in a button click event, we can write the following code.

Code Snippet

private void button1_Click(object sender, EventArgs e)

{

this.treeView1.SelectedNode = treeView1.Nodes[10];

this.treeView1.SelectedNode.EnsureVisible();

this.treeView1.Focus();

}

Best regards,

Bruce Zhou

Bruce.Zhou  Tuesday, December 02, 2008 7:01 AM

Hi riyaz c,

Wecan use EnsureVisible method to make the selected item visible. Suppose we make the selected node to be visible in a button click event, we can write the following code.

Code Snippet

private void button1_Click(object sender, EventArgs e)

{

this.treeView1.SelectedNode = treeView1.Nodes[10];

this.treeView1.SelectedNode.EnsureVisible();

this.treeView1.Focus();

}

Best regards,

Bruce Zhou

Bruce.Zhou  Tuesday, December 02, 2008 7:01 AM
thanks bruce... :)
criyaz  Friday, December 19, 2008 6:25 AM

You can use google to search for other answers

Custom Search

More Threads

• How To Refresh Property Grid while desigining,.
• Objects in Array List
• DataGridViewComboBox Column DataBinding
• AVI and background problem
• Localizing DisplayMember
• Does anyone know how to stop the designer from auto generating columns in the datagridview
• How can a group of changes be merged into a single undoable action in the VS designer?
• Controls are not rendered on the form correctly
• Designer forces DataGridView.AutoGererateColumns = false??
• How to add background color to combobox