Solved

Disabling Menu in a menustrip + vb.net 2008

Posted on 2012-03-12
7
1,968 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Stored Proc - Rewrite 42 61
SQL Query 2 34
SQL Dump exec output to table 3 23
Help with my first SQL CLR table value function 2 13
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

821 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