Get a flattened list of all RadMenuItems in...

2 posts, 0 answers
  1. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 16 Oct 2010 Link to this post


    RadControls for WinForms

    Q2 2010 

    .NET version


    Visual Studio version


    programming language

    C# and VB.NET

    I put together this little function for something that wasn't required in the end but thought it could be quite useful sometimes. 

    This code returns a collection of RadMenuItemBase objects from a given control that contains RadMenuItemBase objects 

    For example: Use it to get back a collection of all RadMenuItemBase objects in RadMenu, RadApplicationMenu, RadSplitButton 
    Public Shared Function GetRadMenuItems(ByVal items As Telerik.WinControls.RadItemCollection) As ReadOnlyCollection(Of RadMenuItemBase)
        Dim returnItems As New List(Of RadMenuItemBase)()
        For Each item As RadMenuItemBase In items
            Dim subItems As ReadOnlyCollection(Of RadMenuItemBase) = GetRadMenuItems(item.Items)
        Dim readOnlyItems As New ReadOnlyCollection(Of RadMenuItemBase)(returnItems)
        Return readOnlyItems
    End Function
    public static ReadOnlyCollection<RadMenuItemBase> GetRadMenuItems(Telerik.WinControls.RadItemCollection items)
        List<RadMenuItemBase> returnItems = new List<RadMenuItemBase>();
        foreach (RadMenuItemBase item in items) {
            ReadOnlyCollection<RadMenuItemBase> subItems = GetRadMenuItems(item.Items);
        ReadOnlyCollection<RadMenuItemBase> readOnlyItems = new ReadOnlyCollection<RadMenuItemBase>(returnItems);
        return readOnlyItems;

    The code can easily be adapted too to get back a flattened collection of items from other types,
    For example: Adapt it and use it to get back a collection of RadtreeNode objects in a RadTreeView
    Public Shared Function GetRadTreeNodes(ByVal nodes As Telerik.WinControls.UI.RadTreeNodeCollection) As ReadOnlyCollection(Of RadTreeNode)
        Dim returnNodes As New List(Of RadTreeNode)()
        For Each node As RadTreeNode In nodes
            Dim subNodes As ReadOnlyCollection(Of RadTreeNode) = GetRadTreeNodes(node.Nodes)
        Dim readOnlyNodes As New ReadOnlyCollection(Of RadTreeNode)(returnNodes)
        Return readOnlyNodes
    End Function
    public static ReadOnlyCollection<RadTreeNode> GetRadTreeNodes(Telerik.WinControls.UI.RadTreeNodeCollection nodes)
        List<RadTreeNode> returnNodes = new List<RadTreeNode>();
        foreach (RadTreeNode node in nodes) {
            ReadOnlyCollection<RadTreeNode> subNodes = GetRadTreeNodes(node.Nodes);
        ReadOnlyCollection<RadTreeNode> readOnlyNodes = new ReadOnlyCollection<RadTreeNode>(returnNodes);
        return readOnlyNodes;

  2. Nikolay
    Nikolay avatar
    1802 posts

    Posted 21 Oct 2010 Link to this post

    Hello Richard,

    Thank you for sharing these code snippets. I have updated your Telerik points accordingly.

    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top