Solved

Disabling Menu in a menustrip + vb.net 2008

Posted on 2012-03-12
7
1,860 Views
Last Modified: 2012-06-21
Hi Experts,

I have menu name names stored in a SQL server table. I need to fetch this menus, loop through them and disable on the main form. I have been unable to to do so. Please assist.
 Private Sub Disablemenus()
        Dim cnn As New SqlConnection(My.Settings.mycString)
        Dim cmd As New SqlCommand
        Dim dr2 As SqlDataReader
        ' Dim cmenuname As ToolStripMenuItem
        cnn.Open()
        cmd.Connection = cnn
        cmd.CommandType = CommandType.Text
        cmd.CommandText = "select MenuName from table1 where Allowed=0)"
        dr2 = cmd.ExecuteReader
        Do While dr2.Read = True
            'disable the menu
        Loop

    End Sub

Open in new window

0
Comment
Question by:Peter Kiprop
  • 4
  • 3
7 Comments
 
LVL 53

Expert Comment

by:Dhaest
ID: 37709183
You probably only have the menu-name in sql-server

Do While dr2.Read = True

    Dim menuStrip As Contexmenu= DirectCast(Form1.Controls.Find(dr2.items["MenuName"]
, True)(0), Contexmenu)
     menuStrip.Enable=True
loop

or

Do While dr2.Read = True
            DisableMenu dr2.items["MenuName"]
Loop



private function DisableMenu(dim menuStrip as string)
        For Each cntrl As Control In Me.components.Components
            If cntrl.Name = menuStrip Then
                'do what ever you need to do
                Exit For
            End If
        Next
end function
0
 
LVL 6

Author Comment

by:Peter Kiprop
ID: 37709277
Hi Dhaest,

None of the above is working. any another suggestion?
0
 
LVL 53

Expert Comment

by:Dhaest
ID: 37709303
And what is not working ? Do you get an error ? How is your menu added to your form ?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 6

Author Comment

by:Peter Kiprop
ID: 37709361
value type form.control cannot be converted to form.contextmenu
0
 
LVL 6

Author Comment

by:Peter Kiprop
ID: 37709447
Hi Dhaest,

i am trying to disable the sub menus and not the main menus. The menus were added manually on the main form using a menustrip control.

Thanks,
Pthepebble.
0
 
LVL 53

Accepted Solution

by:
Dhaest earned 500 total points
ID: 37709802
Did you add a name to each menuitem (below example is based on the text of the subitem)

    Private Sub DisableMenuItem(menuItem As String)
        For Each mnu As ToolStripMenuItem In MenuStrip1.Items
            For Each submnu As ToolStripMenuItem In mnu.DropDownItems
                If (submnu.Text = menuItem) Then
                    submnu.Enabled = False
                End If
            Next
        Next
    End Sub
0
 
LVL 6

Author Closing Comment

by:Peter Kiprop
ID: 37709881
Exactly what i needed. Many thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now