Working with SalesLogix MenuItems

So a question was posted in the SalesLogix Business Partner news groups about working with MenuItems, and specifically with the PopupMenu property of the SalesLogix DataGrid control. I thougt it was worth while to post my reply here as well.

I am trying to get a reference to one of the items in a grids PopupMenu Items collection. I would like to obtain the reference by using the Items caption.  (ex. “My Sub Menu”).

‘attempt to access collection via “name” (i.e. Caption text)
Set oItem = grdControl.PopupMenu.Items(“&Edit…”)  ‘<– fails
Set oItem = grdControl.PopupMenu.Items(“Edit…”)  ‘<– fails
‘attempt to use Find method that appears to take a Caption text as an argument
Set oItem = grdControl.PopupMenu.Items.Find(“&Edit…”)  ‘<– fails
Set oItem = grdControl.PopupMenu.Items(“Edit…”)  ‘<– fails

Here is my reply:

Well, you could always just iterate though the items. Checking the caption property of each to see if it is the one you are looking for (and I’d replace off any ‘&’ from the caption since you could not reliably know where it is in the string as they are often auto-assigned).

Wouldn’t be too bad – not like you’re going to have a thousand items to iterate through, probably only looking at a handful of items tops. I did something similar to this where I dynamically filled the PopupMenu based on the fields that appeared in the query the grid was bound to. Ran fast. Similarly, you’d see really very little difference in speed if you iterated though them to find the one you’re looking for. Know what I mean?

However, for readability of your code it would be much nicer to be able to just reference an item in the collection. I hate to tell you this. It works for me (with a caveat – keep reading).

I have a DataGrid PopupMenu with 3 custom items in it, Tester 1, Tester 2, and Yeye Tester. I run this code, and it works fine.

Sample Menu
    – Tester 1
    – Tester 2
    – Yeye Tester

Dim item

    Set item = DataGrid1.PopupMenu.Find(“Yeye Tester”)
    If Not item Is Nothing Then
        MsgBox “I found ” & item.Caption
        MsgBox “not found”
    End If

The reason why this works is that all MenuItems are top level MenuItems. Here’s probably why it is failing for you. The “Find” method applies to the collection for the current MenuItem only. Each MenuItem has an “Items” collection of children MenuItems. Each subitem is contained in the collection of it’s respective parent. Opening the SalesLogix Controls with an object browser, you’ll see that the Find method is a method of the MenuItem, not of the PopupMenu. This leads me to believe it applies only to that particular MenuItem’s “Items” collection. If you wanted to use Find in the case with sub groups of menu items you’d actually have to iterate through all top level items to call Find for each of their Items collections. So the Find method of the PopupMenu is searches it’s own immediate Items collection. In your case, it is likely that the MenuItem you’re looking for is a sub-item of another MenuItem. So, when searching the Items collection of a given MenuItem, you need to recursively run down the tree of MenuItems in the collection, checking also each of their Items collections as well. One thing to point out here, the PopupMenu property of the SalesLogix DataGrid control is of type MenuItem, it is not of type PopupMenu as it’s name would imply. So as the PopupMenu property of the DataGrid is nothing more than a MenuItems object, when you call Find on PopupMenu, you are simply calling Find on the top level MenuItems only (or basically the MenuItems that exist in the top MenuItem (the one named PopupMenu exposed on the grid)

Sample Menu
    – Tester 1
    – Tester 2
        – Sub Tester 2a
            – Yeye Tester
            – Bobo Tester
        – Sub Tester 2b
    – Tester 3

Let’s say we want to find ‘Yeye Tester’. What you need to do is recursively move down the tree calling Find for each MenuItem. Here’s a sample that should work for you.

Function MenuItemFind(popupmenu, menucaption)
Dim item
Dim i
    Set item = popupmenu.Find(menucaption)
    If Not item Is Nothing Then
        Set MenuItemFind = item
        Exit Function
        For i = 0 To popupmenu.Count – 1
            On Error Resume Next
            Set item = MenuItemFind(popupmenu.Items(i), menucaption)
            If Not item Is Nothing Then Set MenuItemFind = item
            On Error GoTo 0
    End If
End Function

Basically, this does just what is needed. A recursive function to call find on the Items collection of each MenuItem in the tree. Now to use it, all you need to do is make a single call:

Dim item

    Set item = MenuItemFind(DataGrid1.popupmenu, “Yeye Tester”)
    ‘It is a good idea to make sure it actually found the MenuItem with the caption supplied
    If Not item Is Nothing Then
        MsgBox “I found ” & item.caption
        MsgBox “Not found”
    End If

Well, that is it in a very long and drawn out nutshell. Have fun.

-Ryan Farley


Ryan Farley

Ryan Farley is the Director of Development for Customer FX and creator of He's been blogging regularly about SalesLogix, now Infor CRM, since 2001 and believes in sharing with the community. His new passion for CRM is Creatio, formerly bpm'online. He loves C#, Javascript, web development, open source, and Linux. He also loves his hobby as an amateur filmmaker.

1 Comment

  1. Thanks a bunch, this helped me! 🙂

    I’m just a coop this quarter and am just learning how to develope for SalesLogix, so this site is now a bookmark for references/issues.


Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe To Our Newsletter

Join our mailing list to receive the latest Infor CRM (Saleslogix) and Creatio (bpm'online) news and product updates!

You have Successfully Subscribed!