Wrox Programmer Forums
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2007, 09:23 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yandisophian
Default String to Tollstripmenuitem

Dear all,
I'm a beginner in vb, try to make an application than can filter menu to be shown for a user in the database.

I save the menuname in the database, so I can get the menu wich allowed to be shown for the user.

But the problem is :
I can not use the data (string) from that table to be use as object to show the menu.

example:
User "A" have "mnReports" in the table, so if "A" log in to the application, i use to change the property of the menu like this :

frmMain.mnReports.visible = true

but the problem is that I can not use the string "mnReports" as the frmmain's object.

Could someone give me some help?

Thank you,

YANDI
 
Old February 12th, 2007, 10:47 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yandisophian
Default

Help me please...

 
Old February 12th, 2007, 11:22 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Here are 2 thoughts:

First: Create 1 menu with every possible option that say an Administrator could use. So say you have 8 menu items but user A should only see 5 of them so you can do 1 of 2 things here: store which fields a user can see in the database and then write program logic to handle which menus should be hidden and which should be visible or the second thing would be to hard code into your application the program logic on which menus are hidden and which are shown. (The database option is much more flexible in my opinion)

Your second option would be to create your menus at Runtime so user A logs in, your application would enter a routine where it adds items to the menu (obviously this option is dynamic) so you would have to add event handlers to each item as it was created or your Click event will not raise a handler.

I know you are a beginner so if you have more questions post them here and someone is bound to answer them ^^

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
 
Old February 13th, 2007, 06:38 AM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yandisophian
Default

hello dparson.
Thanks for your answer.

Yes, i've took the first way from your suggestion.
I've create a menu, say 8 menu. Then I create 2 table for the user to write which menu should be shown for every user.

Structure of table 1:
UserName, Password

Structure of table 2:
UserName, mnName

The type of mnName is nvarchar

So I can get which mnName that allowed for a user.

But the type of mnName is string.

The problem is How to use the mnName that I take from the table (which have string type) to use as an object name to make the menu visible.

example: I can have the variable mnName= "mnFile"
but I can not write : mnName.visible= True because the mnName type is string.


Thanks.


 
Old February 13th, 2007, 08:43 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

After your user logs in, you know what menu you want to display because it is stored in your table, so try this:
        '* Loop through each control on your form
        '* and only look at the MenuStrips.

        For Each ctrl As Control In Me.Controls
            If TypeOf ctrl Is MenuStrip Then
                If ctrl.name = "your MenuStrip name here" Then
                    ctrl.visible = true
                End If
            End If
        Next




Best Regards,
Earl Francis
 
Old February 13th, 2007, 09:27 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yandisophian
Default

Thank Earl,
But I only have 1 menu strip. What I want is to visible the toolstripmenuitem.

I've try this:

For each mnItem as toolstripmenuitem in frmMain
   if mnItem.Name = strmnName then
      mnItem.visible=true
   end if
Next

It's work for just the main menu, not for the its dropdown item.

File, Edit is the main menu
and Exit is the dropdown for the File.

Thanks again for your answer.
Can anyone give me another suggestion?



 
Old February 14th, 2007, 08:56 AM
Authorized User
 
Join Date: Nov 2006
Posts: 87
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ef1196
Default

Instead of "mnItem.Name", look at "mnItem.Text" and also expose the "DropDownItems" collection. You can iterate through these as follows:
        For Each menuItem As ToolStripMenuItem In mnuMain.Items
            For intX As Integer = 0 To menuItem.DropDownItems.Count - 1
                If menuItem.HasDropDownItems Then
                    If menuItem.DropDownItems(intX).Text = "Your Search Text" Then
                        '* your code here
                    End If
                Else
                    If menuItem.Text = "Your Search Text" Then
                        '* your code here
                    End If
                End If
            Next
        Next

I agree with Doug Parsons, in that the best way to implement a strategy such as this would be to have it derive its choices from a table.



Best Regards,
Earl Francis
 
Old February 14th, 2007, 08:56 PM
Registered User
 
Join Date: Jun 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to yandisophian
Default

Thank you so much Earl, it's work.

I very appreciate for your help.

:)

Regards,
YANDI






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find a string in another string in vb6 satish_k VB How-To 3 March 30th, 2007 12:17 PM
Casting String array to string Samatha ASP.NET 1.0 and 1.1 Professional 1 December 5th, 2006 07:46 AM
syntax to find a string in a string cole SQL Server 2000 2 October 10th, 2005 06:06 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.