how to fine an menu item?

  • Thread starter Thread starter Peter van der Veen
  • Start date Start date
P

Peter van der Veen

Hi

I have a contextmenu and i want to add to one of the items a submenu
item. I only have the name of item and want to know the index value.
How to do that?


Peter
 
Peter van der Veen said:
I have a contextmenu and i want to add to one of the items a
submenu item. I only have the name of item

A MenuItem does not have a Name property. You mean the variable name? There
might be several variables with different names pointig to the same
MenuItem.
and want to know the index
value. How to do that?

The MenuItem has an Index property.
 
I know, but i need to find that index nummer.

an example

i've create a vew menu items

contextmenu1.items.add("Test1")
contextmenu1.items.add("Test2")
contextmenu1.items.add("Test3")

(in the prorgram the names are from a recordset)

so i've 3 menu items

now i want later in the code add an submenu to lets say test2.
I don't know the index and want to know it. than i can use it to add
the submenu

How do i find the indexnumber of the menuitem with the text "Test2"
 
Peter van der Veen said:
I know, but i need to find that index nummer.

an example

i've create a vew menu items

contextmenu1.items.add("Test1")
contextmenu1.items.add("Test2")
contextmenu1.items.add("Test3")

(in the prorgram the names are from a recordset)

so i've 3 menu items

now i want later in the code add an submenu to lets say test2.
I don't know the index and want to know it. than i can use it to
add the submenu

How do i find the indexnumber of the menuitem with the text
"Test2"


dim Item as menuitem
item = contextmenu1.items.add("Test2")


'later:
item.menuitems.add ....


Why do you identify the item by the text? If the text changes, you mustn't
forget to change the code when finding the Item by it's text because the
string can not be evaluated by the compiler. Isn't there a logic that tells
you to which item the subitems have to be added? Something like "It is the
item that...". Currently the answer is "..that shows the text 'Test2'".
 
The menu and submenus are dynamilcaly genereted at runtime. These were
just examples.
The menus and submenus are stored in a database and users can change
them so i don't know the position of the menus (indexnumber)
 
Peter van der Veen said:
The menu and submenus are dynamilcaly genereted at runtime. These
were just examples.
The menus and submenus are stored in a database and users can
change them so i don't know the position of the menus
(indexnumber)

So you probably have a primaryKey in your database identyfing the MenuItem?
You might add the menuitems to a hashtable using the PK as the key.
 
Back
Top