RonB RonB - 4 months ago 27
Vb.net Question

Cannot read the visible attribute of a menuitem properly

In the following code, the IF statement:

If mnuSubItem1.Visible = False And mnuSubItem2.Visible = False Then
mnuMainMenuItem.Visible = False
End If


Always results as true, regardless of the visible states of subitem1 and subitem2?
If mnuSubItem1.visible = true and mnuSubItem2.visible = false
the code within the
IF
statement still executes.

What am I doing wrong here?

Answer

I think you are using this Items as sub menu items, like this:

mnuMainMenuItem -> mnuSubItem1 & mnuSubItem2

When mnuMainMenuItem is closed, mnuSubItem1 & 2 are not visible. So the program decide to execute the if statement.

Visible = False

Visible = True

Use this code to reach your goal:

mnuMainMenuItem.ShowDropDown()
If mnuSubItem1.Visible = False And mnuSubItem2.Visible = False Then
    mnuMainMenuItem.Visible = False
End If
mnuMainMenuItem.HideDropDown()