MenuItem.Index ?

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…).

Did I do something wrong ?

For the record, the used code was:

MsgBox "This is the selected MenuItem Properties" + EndOfLine + EndOfLine +_ "MenuItem Name: " + Me.Text + EndOfLine +_ "MenuItem Index: " + Str(Me.Index)

the code is located in the If / End If block that remove a selected MenuItem.

Index property is for arrays.
So individual menu items have no index.

Hi Christian,

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).

Hi Eli,

thank you for your answer.

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).

Niiiiice !

Why so?

Good question…

OK, I know. Back to the MenuItem SubClass: how do I know the index of the selected MenuItem to be deleted ?

Acutally, I use Me.Text because Me.Index is not a value in the 0 - # of MenuItems in “Me”.

I came from there.

I still may be wrong thinking. I only wanted to understand where I am wrong.`

I forgot what you wrote earlier: If you have a menu item array.

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

Thanks Eli, I understand.

In my case, I have a FolderItem in the Tag property and I use MenuItem.Remove(Me.Text) to delete the menuItem (in Action of the Menu SubClass).

I probably would never think to put this kind of code there. I have to try to more open my mind.