wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu
wierd behavior in merged menu wierd behavior in merged menu
wierd behavior in merged menu
Go Back  Xtreme Visual Basic Talk > > > wierd behavior in merged menu


Reply
 
Thread Tools Display Modes
  #1  
Old 09-03-2013, 12:07 PM
Snetzky Snetzky is offline
Freshman
 
Join Date: Dec 2009
Location: Iowa
Posts: 26
Default wierd behavior in merged menu


I am using .xml files to create dynamic menus that get loaded at runtime. Each main menu item has a "SecLevel" attribute that I assign to the tag of the menu which gets used against the users usergroup priveleges to determine if the menu gets enabled or not.

I have an application menu which should always be displayed. Rather than repeat the application .xml in every other file, I decided to try to use MenuMerge to merge in the function menu in after the fact.

Once I have the two menus merged, I run a routine to set the enabled property based on the user security (based on comparing the user rights to the menu item tag property). Oddly enough, it works if I load everything in one file, but if I do it as a merge, the tag doesn't appear to be set in the second menu when it gets loaded which means none of my security levels are set in the UI.

Any idea what I might be doing wrong? Here's the code:

Code:
Public Class fw_FormMain
    'Declare objects for tracking current user and subapplication
    Public _CurrentUser As fw_User
    Public _CurrentApp As String

    Private Sub FormMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        _CurrentUser = New fw_User
        txtUser.Text = _CurrentUser.FirstName & " " & _CurrentUser.LastName
        LoadApplicationMenu()

    End Sub

    'This event is used to handle all events from the Application Menu
    Private Sub MenuItemOnClick_Application(ByVal sender As Object, _
                    ByVal e As System.EventArgs)
        Dim sApp As String
        Dim iPos As Integer
        sApp = sender.ToString
        iPos = sApp.IndexOf("&")
        _CurrentApp = sApp.Substring(iPos + 1)
        'Look up the application menu to load.
        'Load Function Menu for Application Selected
        LoadFunctionMenu(_CurrentApp)



    End Sub

    'This event should handle everything from the navigation menu
    Private Sub MenuItemOnClick_Navigation(ByVal sender As Object, _
                    ByVal e As System.EventArgs)
        Dim sNavigation As String
        sNavigation = sender.ToString
        'Look up the screen to display in panel based on the Navigation value



    End Sub

    Private Sub MenuItemOnClick_Function(ByVal sender As Object, _
                    ByVal e As System.EventArgs)
        Dim sFunction As String
        sFunction = sender.ToString
        'Look up form to open for function based on the Function Value
    End Sub

    Private Sub LoadApplicationMenu()
        Dim objMenu As New fw_DynamicMenu()
        Dim sMenuPath As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\MenuDefs\"
        'pass the location of the XML Menu - Configuration File
        objMenu.XMLMenuFile = sMenuPath & "Application.xml"
        'pass the Form object to Dynamic Menu so as to associate the Menu _
        'Event handlers
        objMenu.objForm = Me
        'Load dynamic menu and return the Menu handle to Me.Menu object
        Me.Menu = objMenu.LoadDynamicMenu()
        'Set the Form Caption to the current application name
        Me.Text = "Doc Ops WorkCenter - Application"
        Dim iUserSecLevel = _CurrentUser.GetSecLevel("Application")
        For Each MenuItem In Me.Menu.MenuItems
            Dim iMenuSecLevel As Integer = CType(MenuItem.Tag, Integer)
            Debug.Print(MenuItem.Text(), iMenuSecLevel)
            SetSecPermissions(MenuItem, iUserSecLevel)
        Next

    End Sub
    Private Sub LoadFunctionMenu(ByVal sMenu As String)
        Dim objMenu As New fw_DynamicMenu()
        Dim objMnu As Menu
        Dim sMenuPath As String = System.IO.Path.GetDirectoryName(Application.ExecutablePath) & "\MenuDefs\"
        'pass the location of the XML Menu - Configuration File
        objMenu.XMLMenuFile = sMenuPath & sMenu & ".xml"
        'pass the Form object to Dynamic Menu so as to associate the Menu _
        'Event handlers
        objMenu.objForm = Me
        'Load dynamic menu and return the Menu handle to Me.Menu object
        objMnu = objMenu.LoadDynamicMenu
        Me.Menu.MergeMenu(objMnu)
        'Set the Form Caption to the current application name
        Me.Text = "Doc Ops WorkCenter - " & sMenu
        Dim iUserSecLevel = _CurrentUser.GetSecLevel(sMenu)
        For Each MenuItem In Me.Menu.MenuItems
            Dim iMenuSecLevel As Integer = CType(MenuItem.Tag, Integer)
            Debug.Print(MenuItem.Text(), iMenuSecLevel.ToString)
            SetSecPermissions(MenuItem, iUserSecLevel)
        Next
    End Sub
    Private Sub SetSecPermissions(ByVal mi As MenuItem, ByVal iUserSecValue As Integer)

        Dim mnuItem As MenuItem

        For Each mnuItem In mi.MenuItems
            Dim sSeclevel As String = mnuItem.Tag
            Dim iMnuSecLevel = CInt(sSeclevel)
            Debug.Print(mnuItem.Text, iMnuSecLevel)
            If iMnuSecLevel <= iUserSecValue Then
                mnuItem.Enabled = True
            Else
                mnuItem.Enabled = False
            End If
            SetSecPermissions(mnuItem, iUserSecValue)
        Next
    End Sub
Reply With Quote
  #2  
Old 09-03-2013, 12:19 PM
Snetzky Snetzky is offline
Freshman
 
Join Date: Dec 2009
Location: Iowa
Posts: 26
Default Never Mind. Figured it out almost immediately after I posted

I'm going to post this in case someone else gets the same issue.

Apparently, the issue was because I was referencing the wrong menu item collection in the LoadFunctionMenu Procedure

Code:
For Each MenuItem In Me.Menu.MenuItems
            Dim iMenuSecLevel As Integer = CType(MenuItem.Tag, Integer)
            Debug.Print(MenuItem.Text(), iMenuSecLevel)
            SetSecPermissions(MenuItem, iUserSecLevel)
Next
Needed to be


Code:
For Each MenuItem In objMnu.MenuItems
            Dim iMenuSecLevel As Integer = CType(MenuItem.Tag, Integer)
            Debug.Print(MenuItem.Text(), iMenuSecLevel.ToString)
            SetSecPermissions(MenuItem, iUserSecLevel)
Next
because merging the second menu in doesn't truly merge the two menus into one, it just adds the second menu in as a seperate object that has to be referenced by itself.

Thanks for listening.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu wierd behavior in merged menu
wierd behavior in merged menu
wierd behavior in merged menu
 
wierd behavior in merged menu
wierd behavior in merged menu
 
-->