I wanted to use MenuItem1.Remove(Me.Index) (in a MenuItem SubClass), and the Language Reference seems to be OK with that, but
I reported the .Text and .Index properties (to understand before removing a MenuItem) and Me.Index reported a value like this one: -2147483648 instead of a value from 0 to 5 (or 10 or ).
thank you for your answer. I certainly misunderstand something. The relevant part of the Language Reference is:
This example removes the Select All menu item from the Edit menu.
EditMenu.Remove(3)
Now, you can now better understand my question. BUT, your answer can be right and fortunately, I used the other Remove(Me.Text) way to remove a MenuItem. (and that one works).
The Index property is as Christian has said for MenuItem arrays. It has nothing to do with the Index argument in the Remove method.
MenuItem.Remove(index As Integer)
EditMenu.Remove(3) means remove the 4th item in the EditMenu (zero-based).
MenuItem.Index As Integer
If you have a menu item array, this property will act like the index in a control set. For regular menu items it is -2147483648 (which is -2^31 and it is kind of a flag telling the Xojo framework, that the Index is unset).
So, we can use MenuItem.Remove(index As Integer) only when we know the index value When I read this sentence, this looks like an evidence. What I mean is I can delete the MenuItem x from the EditMenu and x value is in the range of available MenuItems.
In my case, in a Dynamically created Menu, this is impossible to do.
BTW: either in the IDE and in my application, EditMenu.Remove(3) does not remove the Select All menu item.
While looking at that, a menu separator is an entry like a MenuItem and can be removed. In my EditMenu, EditMenu.Remove(1) remove the first separator (between Edit.Cancel and Edit.Cut).
Yes, you can loop over the menu items and look at their Text property.
Or upon creating the items dynamically you can attached something to the Tag property. And when you want to remove that dynamically created item, you loop over the menu items and look at their Tag property until the Tag is the same:
Dim item As New MenuItem()
item.Text = "blahblah"
item.Tag = "abc"
EditMenu.Append(item)
For i As Integer = 0 To EditMenu.Count - 1
If EditMenu.Item(i).Tag = "abc" Then
EditMenu.Remove(i)
Exit
End
Next