Solved

Disabling Menu in a menustrip + vb.net 2008

Posted on 2012-03-12
7
1,899 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.

910 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

23 Experts available now in Live!

Get 1:1 Help Now