Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2129
  • Last Modified:

Disabling Menu in a menustrip + vb.net 2008

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
Peter Kiprop
Asked:
Peter Kiprop
  • 4
  • 3
1 Solution
 
DhaestCommented:
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
 
Peter KipropAuthor Commented:
Hi Dhaest,

None of the above is working. any another suggestion?
0
 
DhaestCommented:
And what is not working ? Do you get an error ? How is your menu added to your form ?
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
Peter KipropAuthor Commented:
value type form.control cannot be converted to form.contextmenu
0
 
Peter KipropAuthor Commented:
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
 
DhaestCommented:
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
 
Peter KipropAuthor Commented:
Exactly what i needed. Many thanks
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now