Highlight Select tree node.

9 posts, 0 answers
  1. Arun Kumar
    Arun Kumar avatar
    3 posts
    Member since:
    Dec 2007

    Posted 14 Nov 2008 Link to this post

    I am extending both RAD Tree view and RAD Tree node in to custom controls for business purposses.
    And populating/adding nodes to custom tree view at runtime.

    I am not able to high light (Back color) the selected node in the tree. Im setting the Theme to ControlDefault on my CustomTree view, but this doenst seem to take effect .

    Any thoughts how i can high light selected nodes on RAD tree view ? Im extending the controls only for business reason, i didnt modify a thing in their actuall behavior. Or Is there anything specific that i need to do, to get the themes going on a extended RAD Treeview control ?

    thanks in advance

    Arun

  2. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 18 Nov 2008 Link to this post

    Hi Arun Kumar,

    Thank you for this question.

    When you inherit a control (in this case RadTreeView), you should override the ThemeClassName property. For more information, please refer to the following Knowledge Base article: Inherit themes from RadControls.

    If you have additional questions, feel free to contact me.

    All the best,
    Nikolay
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Arun Kumar
    Arun Kumar avatar
    3 posts
    Member since:
    Dec 2007

    Posted 18 Nov 2008 Link to this post

    Thanks for the reply. I figured that out few days ago, from one of your another post.
    Sorry about the reposting, but the search wasnt really helpful.
  5. D
    D avatar
    7 posts
    Member since:
    Feb 2009

    Posted 17 Feb 2009 Link to this post

    Can you give the VB code to override the ThemeClassName?  I want the nodes to highlight when selected. My tree is created at run time. I am struggling with this and don't know how to code the override to get what I need (I am a junior programmer on first project). I assume I would need either the Telerik or ControlDefault theme or does only one of them highlight and if so which one? Again, I need the VB code from first line to last line to do the override and anything else that I would need to know to get this to work. 
  6. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 17 Feb 2009 Link to this post

    Hi D,

    I updated the Knowledge Base article regarding ThemeClassName with a VB.NET example. As to your scenario where a RadTreeView instance is created runtime, please note that you should call BeginInit/EndInit methods which will apply the theming mechanism:

    Imports Telerik.WinControls.UI  
     
    Public Class Form1  
        Private Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgs) Handles MyBase.Load  
            Dim tree As RadTreeView = New RadTreeView  
            tree.BeginInit()  
            tree.Location = New Point(0, 0)  
            tree.Size = New Size(100, 500)  
            Me.Controls.Add(tree)  
            tree.EndInit()  
     
            Dim node As RadTreeNode = New RadTreeNode  
            tree.Nodes.Add(node)  
        End Sub 
    End Class 

    If you have additional questions, feel free to contact me.

    All the best,

    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. D
    D avatar
    7 posts
    Member since:
    Feb 2009

    Posted 17 Feb 2009 Link to this post

    Thanks.

    The tree nodes are highlighting now. I would appreciate it if you could answer some questions so I understand what is happening. My code is below for reference. I am reading XML files and creating a tree and filling an objecteditpanel with the properties.

    1) The tree that I am getting is the Default Control Theme. What if I want the Telerik Theme with nodes that highlight. What would I need to do?

    2) I added the override but I am not clear on what is being returned. What is " fullname "?
     
    3) I added BeginInit() and EndInit() and nothing changed.  Is it in the correct place? Do I need it? Should I delete BeginInit() and EndInit() ? See my code below.

    4) There are several lines of commented code. When I could not get the tree to highlight with the Theme, I put a border around the selected node and saved the level and index. When the next node was selected I put a border around it and tried to remove the border from the previous node by using the level and index of the prior node and changing the border to transparent. I kept getting an error regarding the indexes being outside or negative. However they were exactly what they should have been when I went through the code with breakpoints. I would like to know what I could have done to make it work this way. When I can't get something to work, I try another way. Of course, I won't use this method now that your suggestions have worked but I still want to know what was wrong with the code, if possible.
     

    5) FYI: The RadCustomButtonTestVB file converted with 10 errors so I was not able to look at it.

    Code:
    Public Class Tree

     I

    nherits RadTreeView

     

     

     

    Public Overrides Property ThemeClassName() As String

     

     

     

    Get  

     Return GetType(RadTreeView).FullName

     

     

     

    End Get

     

     

     

     

    Set(ByVal value As String)

     

     

     

    End Set

     

     

     

     

    End Property

     

     

     

     

    Private hRecord As NVEAData.Record

     

     

     

    Private hObjectEditPanel As ObjectEditPanel

     

     

     

    Private vPanel As String = "False"

     

     

     

    Private vRecord As String = "False"

     

     

     

     

    Private vNodeSelected As String = "False"

     

     

     

     

    Public Property Record() As NVEAData.Record  

     

     

     'Public vPreviousNodeLevel As Integer = 0

     

     

     

     

    'Public vPreviousNodeIndex As Integer = 0

    Get

     

     

    Return hRecord

     

     

     

    End Get

     

     

     

     

    Set(ByVal value As NVEAData.Record)

     

     

      hRecord = value

     

    If IsNothing(hRecord) Then

     

     

     

     

    Return

     

     

     

     

    End If

     

     

     

     

    BeginInit()

     

     

      vRecord = 

     "True"

     

     

     

     

    Nodes.Clear() 'clears tree - otherwise another tree is concatenated to previous tree

     

     

     

     

    Dim Node1 As New RadTreeNode(hRecord.Name) 'Declare Top Node on Tree

     

     

     

     

    Nodes.Add(Node1) 'Add Top Node on Tree

     

     

     

     

    WriteRecordNodes(Node1, hRecord) 'Loads all nodes below the top node

     

     

     

     

    Node1.ExpandAll() 'Expands the entire tree below the top node

     

     

     

     LoadRecordIntoEditPanel() 'Load Edit Panel with Top Node

     

     

     

    EndInit()

     

     

     

    End Set

     

     

     

     

    End Property

     

     

     

     

    Public Property ObjectEditPanel() As ObjectEditPanel

     

     

     

    Get

     

     

     

     

    Return hObjectEditPanel

     

     

     

    End Get

     

     

     

     

    Set(ByVal value As ObjectEditPanel)

     

     

     hObjectEditPanel = value

     

    If IsNothing(hObjectEditPanel) Then

     

     

     

     Return

     

     

     

    Else

     

     

     

     

    vPanel = "True"

     

     

     

     

    LoadRecordIntoEditPanel()

     

     

     

    End If

     

     

     

     

    End Set

     

     

     

     

    End Property

     

     

     

     

    Public Sub WriteRecordNodes(ByVal Node As RadTreeNode, ByVal hrecord As Record)

     

     

      Node.Text = hrecord.Name

     Node.Tag = hrecord

     

    For Each c As iRecordCollection In hrecord.Collections

     

     

     

     

     

    For Each r As Record In c

     

     

    Dim vnode As New RadTreeNode

     

     

      Node.Nodes.Add(vnode)

    WriteRecordNodes(vnode, r)

     

    Next

     

     

     

     

    Next

     

     

     

     

    End Sub  

     

     

     

     

     

    Public Sub LoadRecordIntoEditPanel()

     

    If vRecord = "True" And vPanel = "True" Then

     

     

     

     

    If vNodeSelected = "True" Then

     

     

     

     

    ObjectEditPanel.Record = CType(SelectedNode.Tag, Record)

     

     

     

    'Nodes(vPreviousNodeLevel).Nodes(vPreviousNodeIndex).BorderColor = System.Drawing.Color.Transparent

     

     

     

     

    'SelectedNode.BorderColor = System.Drawing.SystemColors.ActiveBorder

     

     

     

     

    'vPreviousNodeLevel = SelectedNode.Level

     

     

     

     

    'vPreviousNodeIndex = SelectedNode.Index

     

     

     

     

    'MessageBox.Show(vPreviousNodeLevel.ToString & "," & vPreviousNodeIndex.ToString)

     

     

     

     

    Else

     

     

     

     

     

     

    ObjectEditPanel.Record = hRecord

     

     

    End If

     

     

     

     

    End If

     

     

     

     

    End Sub

  8. D
    D avatar
    7 posts
    Member since:
    Feb 2009

    Posted 17 Feb 2009 Link to this post

    I got a message that I unsubscribed from this thread. I must have clicked on something in error.  I do want an answer to my previous reply that had my code and about 5 questions about your solution.

    Thanks again.
  9. D
    D avatar
    7 posts
    Member since:
    Feb 2009

    Posted 18 Feb 2009 Link to this post

    Thanks.

    The tree nodes are highlighting now. I would appreciate it if you could answer some questions so I understand what is happening. My code is below for reference. I am reading XML files and creating a tree and filling an objecteditpanel with the properties.

    1) The tree that I am getting is the Default Control Theme. What if I want the Telerik Theme with nodes that highlight. What would I need to do?

    2) I added the override but I am not clear on what is being returned. What is " fullname "?
     
    3) I added BeginInit() and EndInit() and nothing changed.  Is it in the correct place? Do I need it? Should I delete BeginInit() and EndInit() ? See my code below.

    4) There are several lines of commented code. When I could not get the tree to highlight with the Theme, I put a border around the selected node and saved the level and index. When the next node was selected I put a border around it and tried to remove the border from the previous node by using the level and index of the prior node and changing the border to transparent. I kept getting an error regarding the indexes being outside or negative. However they were exactly what they should have been when I went through the code with breakpoints. I would like to know what I could have done to make it work this way. When I can't get something to work, I try another way. Of course, I won't use this method now that your suggestions have worked but I still want to know what was wrong with the code, if possible.
     
    5) FYI: The RadCustomButtonTestVB file converted with 10 errors so I was not able to look at it.

    Code:
    Public Class Tree
    I
    nherits RadTreeView
    Public Overrides Property ThemeClassName() As String
      Get
          Return GetType(RadTreeView).FullName
     
    End Get
      Set
    (ByVal value As String)
      End
    Set
    End
    Property
    Private
    hRecord As NVEAData.Record
    Private hObjectEditPanel As ObjectEditPanel
    Private vPanel As String = "False"
    Private vRecord As String = "False"
    Private vNodeSelected As String = "False"
    Public Property Record() As NVEAData.Record  
    'Public vPreviousNodeLevel As Integer = 0
    'Public vPreviousNodeIndex As Integer = 0
    Get
        Return
    hRecord
    End Get
    Set
    (ByVal value As NVEAData.Record)
         hRecord = value
        
    If IsNothing(hRecord) Then
             Return
         End
    If
        
    BeginInit()
         vRecord =
     "True"
        
    Nodes.Clear() 'clears tree - otherwise another tree is concatenated to previous tree
        
    Dim Node1 As New RadTreeNode(hRecord.Name) 'Declare Top Node on Tree
        
    Nodes.Add(Node1) 'Add Top Node on Tree
        
    WriteRecordNodes(Node1, hRecord) 'Loads all nodes below the top node
         
    Node1.ExpandAll() 'Expands the entire tree below the top node
        
     LoadRecordIntoEditPanel() 'Load Edit Panel with Top Node
        
    EndInit()
    End Set  

    End Property
    Public
    Property ObjectEditPanel() As ObjectEditPanel
    Get
       Return
    hObjectEditPanel
    End Get
    Set
    (ByVal value As ObjectEditPanel)
       hObjectEditPanel = value
       If IsNothing(hObjectEditPanel) Then
            Return
       Else  
            
    vPanel = "True"
           
    LoadRecordIntoEditPanel()
       End If
    End
    Set
    End
    Property
    Public
    Sub WriteRecordNodes(ByVal Node As RadTreeNode, ByVal hrecord As Record)
      Node.Text = hrecord.Name
      Node.Tag = hrecord
      For Each c As iRecordCollection In hrecord.Collections
          For Each r As Record In c
              Dim vnode As New RadTreeNode
              Node.Nodes.Add(vnode)
              WriteRecordNodes(vnode, r)
        
    Next
     Next
    End
    Sub
    Public
    Sub LoadRecordIntoEditPanel()
    If vRecord = "True" And vPanel = "True" Then
        If
    vNodeSelected = "True" Then
             
    ObjectEditPanel.Record = CType(SelectedNode.Tag, Record)
            
    'Nodes(vPreviousNodeLevel).Nodes(vPreviousNodeIndex).BorderColor = System.Drawing.Color.Transparent
             'SelectedNode.BorderColor = System.Drawing.SystemColors.ActiveBorder
             'vPreviousNodeLevel = SelectedNode.Level
             'vPreviousNodeIndex = SelectedNode.Index
             'MessageBox.Show(vPreviousNodeLevel.ToString & "," & vPreviousNodeIndex.ToString)
      
    Else
            
    ObjectEditPanel.Record = hRecord
       End If
    End
    If
    End
    Sub

  10. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 23 Feb 2009 Link to this post

    Hello D,

    Please find the answers to your questions below:
    1. If you want to use the Telerik theme, you should drag and drop the TelerikTheme component on the form. Then, you should set the ThemeName property of the RadTreeView instance to Telerik.
    2. The FullName returns the fully qualified name of the Type, including its namespace. So, for RadTreeView the FullName is Telerik.WinControls.UI.RadTreeView. For additional information, refer to MSDN.
    3. You should call BeginInIt/EndInIt for the runtime created instances of your RadTreeView. You should not use them in the class that inherits RadTreeView class.
    4. Please find the answer to this question in your support ticket about the same topic.
    5. Most probably you do not have the latest version Q3 2008 SP2 (v8.2.0.0) and therefore you are getting the compile errors. Please update your version to the latest one and try again.
    Best wishes,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for WinForms is Visual Studio 2017 Ready