Moving UP and Down in radtreeview by button (winform)

5 posts, 0 answers
  1. Aqueel
    Aqueel avatar
    1 posts
    Member since:
    May 2008

    Posted 21 May 2008 Link to this post

    Hi,

    I just want my user to to select a node and then use a button (up or down) to move in the treeview.  I have seen example but they related to ASP.Net.  I would like to do the same in WinForm.

    I also tried using the radListbox and achived the desired functionality of moving Up and Down. However  with radListbox  I have different problem.  The problem is, I want users to check and uncheck an item in the list.  I can not figure out how I make radListbox items to appear with check box.

    Any help in above to problem will be highly appreciated.


  2. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 22 May 2008 Link to this post

    Hello Aqueel,

    Here is the code that I used to move the selected node up and down with two buttons:
    1 private void btnUp_Click(object sender, EventArgs e) 
    2         { 
    3             RadTreeNode selectedNode = this.radTreeView1.SelectedNode; 
    4             if (selectedNode == null
    5             { 
    6                 this.radTreeView1.SelectedNode = this.radTreeView1.LastVisibleNode; 
    7                 return
    8             } 
    9  
    10             RadTreeNode prevVisible = selectedNode.PrevVisibleNode; 
    11             if (prevVisible != null
    12             { 
    13                 this.radTreeView1.SelectedNode = prevVisible; 
    14  
    15                 int treeViewTop = this.radTreeView1.ClientRectangle.Y - this.radTreeView1.ScrollPosition.Y; 
    16                 if (prevVisible.Bounds.Top <= treeViewTop) 
    17                 { 
    18                     this.radTreeView1.ScrollBy(1); 
    19                 } 
    20             } 
    21         } 
    22  
    23         private void btnDown_Click(object sender, EventArgs e) 
    24         { 
    25             RadTreeNode selectedNode = this.radTreeView1.SelectedNode; 
    26             if (selectedNode == null
    27             { 
    28                 this.radTreeView1.SelectedNode = this.radTreeView1.FirstVisibleNode; 
    29                 return
    30             } 
    31              
    32             RadTreeNode nextVisible = selectedNode.NextVisibleNode; 
    33             if (nextVisible != null
    34             { 
    35                 this.radTreeView1.SelectedNode = nextVisible; 
    36  
    37                 int treeViewBottom = this.radTreeView1.ClientRectangle.Y -  
    38                     this.radTreeView1.ScrollPosition.Y + this.radTreeView1.ClientRectangle.Height; 
    39                 if (nextVisible.Bounds.Bottom > treeViewBottom) 
    40                 { 
    41                     this.radTreeView1.ScrollBy(-1); 
    42                 } 
    43             } 
    44         } 

    Regarding your other question you can take a look at this KB article that describes how to have check boxes in a RadComboBox. This should work for RadListBox with little changes.

    If you have any additional questions, please contact me.

    Kind regards,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Mike
    Mike avatar
    76 posts
    Member since:
    Nov 2004

    Posted 12 Jun 2008 Link to this post

    Hi Telerik,

    I have expanded on this example because I needed cyclical navigation in the treeview, but I’m running into issues.

    If the user is at the top of the tree and they click btnup they should move to the bottom (last node) in the tree, and if the user is at the bottom of the tree and click btndown they should move to the top of the tree.

    Moving to the top of the tree works fine.  I just get the root node of the tree and select it, but for some reason I cannot get the last node of the tree.

    Here is the code I added…

    In btnup_click add this else condition to the last if statement.

                        else

                        {

                            this.tvwrDocVariables.SelectedNode = selectedNode.RootNode;

                            AppRadTreeViewScrollHelper.ScrollToNode(this.tvwrDocVariables, selectedNode.RootNode);

                        }

     

    In the btndown_click add this else condition to the last if statement.

      else

                        {

                            this.tvwrDocVariables.SelectedNode = this.tvwrDocVariables.LastVisibleNode;

                            AppRadTreeViewScrollHelper.ScrollToNode(this.tvwrDocVariables, this.tvwrDocVariables.LastVisibleNode);

                        }

    Oh…  I also implimented your scrollhelper class from a previous post.

    The LastVisibleNode call in the btndown returns a null value for the node.  What am I doing wrong?

    Many thanks,

    ~Mike

     

  5. Jordan
    Admin
    Jordan avatar
    547 posts

    Posted 16 Jun 2008 Link to this post

    Hi mike scardina,

    Thank you for writing.

    There was an issue in the LastVisibleNode property that caused it to return null in certain cases - for example if you set a node that has no children to be expanded. The issue has now been addressed and will not be present in our next release.

    For now you can use the following method to find the last visible node in a RadTreeView:
    private RadTreeNode GetLastVisibleNode(RadTreeNodeCollection nodes) 
            { 
                if (nodes != null
                { 
                    RadTreeNode node = null
                    for (int i = nodes.Count - 1; i >= 0; i--) 
                    { 
                        node = nodes[i]; 
                        if (node.Visible) 
                        { 
                            if (!node.Expanded || node.Nodes.VisibleCount == 0) 
                            { 
                                return node; 
                            } 
                            return RadTreeNode.GetLastVisibleNode(node.Nodes); 
                        } 
                    } 
                } 
                return null
            } 

    You invoke it as shown below:

    RadTreeNode lastVisibleNode = this.GetLastVisibleNode(this.radTreeView1.Nodes);

    If you have additional questions, please contact me.

    Sincerely yours,
    Jordan
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 23 Mar 2011 Link to this post

    Hello guys,

    Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.
     
    Kind regards,
    Stefan
    the Telerik team
Back to Top
UI for WinForms is Visual Studio 2017 Ready