Is there any bug with VB.Net ContextMenu ??

  • Thread starter Thread starter I_AM_DON_AND_YOU?
  • Start date Start date
I

I_AM_DON_AND_YOU?

I have written a VB.Net program. This program has a ConetxtMenu1.
ContextMenu1 is very big and has many levels. There are so many procedures
and depending upon the logic many times a menu item would be visible or
hidden.

I have noticed that in one procedure I am setting the value of a menuitem's
visible property as TRUE but still it is invisible in the Menu.

I have even tested by putting the last statement of the procedure which
executes (opens) the contextmenu as menuitem15.visible = true. So to
understand the structure of the code is :

Button1_Click()

code line 1
code line 2
....
....
....
code line 100


me.contextmenu.show(me.button1, new point(0,0) ------------------- this is
second last line of the code
menuitem15.visible = 15 ----------------- this last line of the code

---------

So the menus opens but still the menutime15 is not visible. Whatever might
be written in the code between line 1 to line 100 (i.e. whether menutime15
is set to visilble or hidden) it should be visible becaue the last line of
the code make it visible.)

I have spent 10 hours in solving this..........................whether this
is a bug?

Thanks in advace!
 
* "I_AM_DON_AND_YOU? said:
I have noticed that in one procedure I am setting the value of a menuitem's
visible property as TRUE but still it is invisible in the Menu.

I have even tested by putting the last statement of the procedure which
executes (opens) the contextmenu as menuitem15.visible = true. So to
understand the structure of the code is :

Button1_Click()

code line 1
code line 2
...
...
...
code line 100


me.contextmenu.show(me.button1, new point(0,0) ------------------- this is
second last line of the code
menuitem15.visible = 15 ----------------- this last line of the code

You will have to make the menu item visible before showing the context menu.
 
....and you know what i also have written (before and after showing the
contextmenu statement):

msgbox menuitem15.visible

and message box shows "TRUE". That means menuitem15.visible = True but
still menuitem15 is not visible.
 
I_AM_DON_AND_YOU,
In addition to Herfried's comments.

Can you post the form you are having problems with?

Which version of VS.NET?
Which OS?

Does this occur only while debugging or in release builds also?

Does it occur on other machines, or just your machine?

Hope this helps
Jay
 
i did that "before" , "after", "left", "right", "up", "down" everywhere.

This works:

Private Sub Whatever()
Dim oMenu As New ContextMenu()
oMenu.MenuItems.Add("Test 1")
oMenu.MenuItems.Add("Test 2")
oMenu.MenuItems.Add("Test 3")
oMenu.MenuItems.Add("Test 4").Visible = False
Me.ContextMenu = oMenu
Me.ContextMenu.Show(Button1, New Point(0, 0))
End Sub

So what are you doing differently?
 
Can you post the form you are having problems with?
It's a solution with 2 projects. First project 3 form. Second Project is a
setup project.
Which version of VS.NET?
(Visual Studio.Net (.Net Framework 1.0))

Which OS?
Windows 2000 Server (SP3)
Does this occur only while debugging or in release builds also? Both.


Does it occur on other machines, or just your machine?
Noted tested (because still in development)

Hope this helps
????
 
I am storing some values (in notepad) 0's and 1's depending upon whether
user wants to hide/unhide a menu. This user do by checking/unchecking
check-box. For example on a form there are 100 check boxes which shows the
title of the contextmenu. User check which items (s)he wants to see on the
contextmenu. So I am saving the selection in notepad and when user clicks a
button I am reading that notepad file to make visible = true if it is 0 and
false if it is.

Let's for the argument sake say there could be some logical error and that's
why it's is set visible = true. But as I wrote earlier right before I am
displaying the contextmenu I am setting menuitem15.visible = true then it
should be displayed. But it is not.


_Andy_ said:
i did that "before" , "after", "left", "right", "up", "down" everywhere.

This works:

Private Sub Whatever()
Dim oMenu As New ContextMenu()
oMenu.MenuItems.Add("Test 1")
oMenu.MenuItems.Add("Test 2")
oMenu.MenuItems.Add("Test 3")
oMenu.MenuItems.Add("Test 4").Visible = False
Me.ContextMenu = oMenu
Me.ContextMenu.Show(Button1, New Point(0, 0))
End Sub

So what are you doing differently?
 
I am storing some values (in notepad) 0's and 1's depending upon whether
user wants to hide/unhide a menu. This user do by checking/unchecking
check-box. For example on a form there are 100 check boxes which shows the
title of the contextmenu. User check which items (s)he wants to see on the
contextmenu. So I am saving the selection in notepad and when user clicks a
button I am reading that notepad file to make visible = true if it is 0 and
false if it is.

Let's for the argument sake say there could be some logical error and that's
why it's is set visible = true. But as I wrote earlier right before I am
displaying the contextmenu I am setting menuitem15.visible = true then it
should be displayed. But it is not.

Ok, post the code for the button_click function. But quickly to
confirm: you are adding to a ContextMenu object, then applying the
ContextMenu to the form, and then showing it. Yes?
 
Ok, post the code for the button_click function. But quickly to
confirm: you are adding to a ContextMenu object, then applying the
ContextMenu to the form, and then showing it. Yes?

Yes.

Ok. So here is the code written in the button. When for the first time I
click this button it shows the menuitem GLS10. However when I when some
values are changed in the mymenu.txt then it doesn't display. However the
last-line of the code is setting the value of GLS10 as visible = true. The
message box shows "TRUE". But the GLS10 doesn't show-up. (I have delete most
of the code which I think would have any impact on overall procedure)



Dim fpath As String
fpath = Application.StartupPath & "\mymenu.txt"
Dim fst As New FileStream(fpath, FileMode.Open)
Dim sr As StreamReader
sr = New StreamReader(fst)
TextBox1.Text = sr.ReadToEnd

sr.Close()
fst.Close()

Dim row1 As String
Dim row2 As String

row1 = TextBox1.Lines(1)
row2 = TextBox1.Lines(2)

If row1.Substring(0, 1) = "1" Then
GL.Visible = True
Else
GL.Visible = False
End If

If row1.Substring(1, 1) = "1" Then
AP.Visible = True
Else
AP.Visible = False
End If

If row1.Substring(2, 1) = "1" Then
AR.Visible = True
Else
AR.Visible = False
End If

If row1.Substring(3, 1) = "1" Then
CA.Visible = True
Else
CA.Visible = False
End If

If row1.Substring(4, 1) = "1" Then
FS.Visible = True
Else
FS.Visible = False
End If

If row1.Substring(5, 1) = "1" Then
INV.Visible = True
Else
INV.Visible = False
End If

If row1.Substring(6, 1) = "1" Then
BM.Visible = True
Else
BM.Visible = False
End If

If row1.Substring(7, 1) = "1" Then
WO.Visible = True
Else
WO.Visible = False
End If



'***************************


If row2.Substring(0, 1) = "1" Then
GLS10.Visible = True
Else
GLS10.Visible = False
End If

If row2.Substring(1, 1) = "1" Then
GLS20.Visible = True
Else
GLS20.Visible = False
End If

If row2.Substring(2, 1) = "1" Then
GLS30.Visible = True
Else
GLS30.Visible = False
End If

If row2.Substring(3, 1) = "1" Then
GLS40.Visible = True
Else
GLS40.Visible = False
End If

If row2.Substring(4, 1) = "1" Then
GLS50.Visible = True
Else
GLS50.Visible = False
End If


MsgBox(GLS10.Visible)

GLS10.Visible = True

MsgBox("hi")

MsgBox(GLS10.Visible)

Me.ContextMenu1.Show(Me.Button1, New Point(0, 0))
 
Hi Don,

If you could zip up the project (forget the setup one) and post it then we
can have a go. Include everything that we'll need (eg, including a copy of the
notepad file) but not the obj or bin directories (which will be recreated).

Then we can all be talking about the same thing.

Regards,
Fergus
 
Yes.

Ok. So here is the code written in the button. When for the first time I
click this button it shows the menuitem GLS10. However when I when some
values are changed in the mymenu.txt then it doesn't display. However the
last-line of the code is setting the value of GLS10 as visible = true. The
message box shows "TRUE". But the GLS10 doesn't show-up. (I have delete most
of the code which I think would have any impact on overall procedure)

That code works for me. I hard-coded the value of the textbox as:

TextBox1.Text = vbCrLf & "11111111" & vbCrLf & "1"

In my implementation (I snipped some of the menu items). I don't
suppose this is anything to do with the first blank line?
(TextBox1.Lines(index) - index starts at zero). The menu items toggle
quite happily with my replacing 1 with 0 anywhere...
So what's this other code you snipped? Just more menu items?
 
Hi Don,

It would be nice to make that menu code generic rather than have
hard-coded character positions against hard-coded menu items!! Change one and,
'oh, boy - what a lot of editing to be done'. This is prone to error too. ;-)

Even if you don't do that, you can at least shorten your code.

This
If row1.Substring(2, 1) = "1" Then
AR.Visible = True
Else
AR.Visible = False
End If

could be done as:
AR.Visible = (row1.Substring(2, 1) = "1")

If you post your project then it can be tested.

Regards,
Fergus
 
Don,
As Fergus stated, zip the entire project with the form you are having
problems with. We do not need the setup project. The cut & paste code in
your other post is not enough to see what is going on. If we see what is
going on, we can offer better advice on what is wrong.
Not tested (because still in development)
By including the entire form, we can run the form as is on different
versions of .NET & different OSs to help track down where the problem is. As
the problem may be an OS version or .NET version specific issue.
(Visual Studio.Net (.Net Framework 1.0))
I was asking if you are using VS.NET 2002 or VS.NET 2003, it sounds like you
are using VS.NET 2002.

Hope this helps
Jay
 
Back
Top