Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / July 2004



Tip: Looking for answers? Try searching our database.

Seeking a plain and simple control for dynamic menus

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dmb - 28 Jul 2004 20:24 GMT
Hi,

I'm looking for a plain and simple control for defining custom/dynamic menus at
runtime. I'm not needing any thrills like icons, background colors/images etc.,
just a simple, easy to program, menu control.

I've already looked at several places, but all the ones that I did found were
too much for my needs and therefore almost everyone were a nightmare (for me) to
program.

I know the method by using the standard menu of VB with array's, but that isn't
"dynamic" enough for my needs.

I'll appreciate it *very much* if someone could give me a hint!!!!.

Thanks in advance!.
J French - 29 Jul 2004 08:36 GMT
>Hi,
>
[quoted text clipped - 10 lines]
>
>I'll appreciate it *very much* if someone could give me a hint!!!!.

You know that you can have menus in UserControls ?

Also that you can have Control Arrays of menu items that can be Loaded
and Unloaded
I can envisage a structure like this where all the menu items have an
index of 0

Menu1
  Menu2
      Menu3
Menu4
  Menu5
      Menu6

Private Matrix(5, 5) As Object
Private Sub Command1_Click()
  Dim L9&
 
  Set Matrix(1, 1) = mnu1 'Control Array
  For L9 = 1 To 5
      Load Matrix(1, 1)(L9)
  Next
End Sub

It gets more interesting :-

Private Sub Command2_Click()
  Dim L9&, L8&
 
  For L9 = 1 To 2
      Set Matrix(1, L9) = Me.Controls("mnu" + CStr(L9))
      For L8 = 1 To 5
          Load Matrix(1, L9)(L8)
      Next
  Next
     
End Sub

I think that something could be developed from this approach
Wrapped in a UserControl, it might be pretty manageable
dmb - 29 Jul 2004 17:53 GMT
>>Hi,
>>
[quoted text clipped - 51 lines]
>I think that something could be developed from this approach
>Wrapped in a UserControl, it might be pretty manageable

Hi J French,

This looks exactly as what I need!. Thanks. I'm not that experienced yet with
control arrays, so maybe you can help me one little step further ...

I have used your code exactly, but executing command button 2 gives me an
"object already loaded" error at line "Load Matrix(1, L9)(L8)". Button 1 works
ok. Can you tell me what's causing the error?.

Thanks!
J French - 30 Jul 2004 13:26 GMT
<snip>

>Hi J French,
>
[quoted text clipped - 4 lines]
>"object already loaded" error at line "Load Matrix(1, L9)(L8)". Button 1 works
>ok. Can you tell me what's causing the error?.

Sorry, I should have warned you

Click only Command1 or Command2

Your post interested me in something I have been vaguely thinking
about for some time, but do not immediately need, so I started
tinkering

If the 'Matrix' of menus approach looks like what you are after, then
I'll look into this a bit more
dmb - 30 Jul 2004 14:44 GMT
><snip>
>
[quoted text clipped - 17 lines]
>If the 'Matrix' of menus approach looks like what you are after, then
>I'll look into this a bit more

Hi J French,

When I only click on Command2 then I also got an error, but I don't remember
what it was (I'm not behind my dev pc right now).

I think that your solution is what I need, but to be sure I'll explain a bit
more what I want:

I want to create a menu based on a directory structure.

Example of directory structure:

C:\Example\Main1
C:\Example\Main2
C:\Example\Main1\Sub1
C:\Example\Main1\Sub2
C:\Example\Main1\Sub3
C:\Example\Main1\Sub1\SubSub1
C:\Example\Main1\Sub1\SubSub2

This should create two main menu items Main1 and Main2. In the menu Main1 it
should create three submenu's Sub1 to 3. Those submenu's can have submenu's too
.... etc. The number of levels should have no limits; this is the users choice.
Every directory will contains files which should be presented as menu items. So
if the user chooses an menu item it should load that file.

I would appreciate it very much if you can put me on the right track. I'm quite
new to this kind of programming (matrixes), so maybe you can provide me with a
working example. That would be one problem less for me. Let me know what I can
do for you in return then ;). If needed this is my temp email:
news6544ax@mailsnare.net.
J French - 30 Jul 2004 17:56 GMT
<snip>

>I would appreciate it very much if you can put me on the right track. I'm quite
>new to this kind of programming (matrixes), so maybe you can provide me with a
>working example. That would be one problem less for me. Let me know what I can
>do for you in return then ;). If needed this is my temp email:
>news6544ax@mailsnare.net.

Bookmark (I am inebriated)

- if any of you other guys can see where this leads, jump in
J French - 31 Jul 2004 06:56 GMT
<snip>

>Hi J French,
>
>When I only click on Command2 then I also got an error, but I don't remember
>what it was (I'm not behind my dev pc right now).

I think I know what the problem was, it assumed you had set up the
following menu structure using the Menu Editor

mnuMain
....mnu1
.........mnu2

>I think that your solution is what I need, but to be sure I'll explain a bit
>more what I want:
[quoted text clipped - 16 lines]
>Every directory will contains files which should be presented as menu items. So
>if the user chooses an menu item it should load that file.

I think I follow what you are after, but would you not be better off
using a TreeView ?  I don't use them because of the OCX

>I would appreciate it very much if you can put me on the right track. I'm quite
>new to this kind of programming (matrixes), so maybe you can provide me with a
>working example.

The 'matrix' approach is just something I thought would impose a two
dimensional structure on the one dimensional way in which VB menus are
set up

>That would be one problem less for me. Let me know what I can
>do for you in return then ;). If needed this is my temp email:

I'll look into this a bit more, but I have some other problems at
present.

Here is the full form:  FORM1.FRM

VERSION 5.00
Begin VB.Form Form1
  Caption         =   "Form1"
  ClientHeight    =   3195
  ClientLeft      =   165
  ClientTop       =   795
  ClientWidth     =   4680
  LinkTopic       =   "Form1"
  ScaleHeight     =   3195
  ScaleWidth      =   4680
  StartUpPosition =   3  'Windows Default
  Begin VB.CommandButton Command2
     Caption         =   "Command2"
     Height          =   435
     Left            =   1500
     TabIndex        =   1
     Top             =   2100
     Width           =   1095
  End
  Begin VB.CommandButton Command1
     Caption         =   "Command1"
     Height          =   375
     Left            =   1500
     TabIndex        =   0
     Top             =   1440
     Width           =   1095
  End
  Begin VB.Menu mnuMain
     Caption         =   "Menu"
     Begin VB.Menu mnu1
        Caption         =   "M1"
        Index           =   0
        Begin VB.Menu mnu2
           Caption         =   "M2"
           Index           =   0
        End
     End
  End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit

Private Matrix(5, 5) As Object
Private Sub Command1_Click()
  Dim L9&
 
  Set Matrix(1, 1) = mnu1 'Control Array
  For L9 = 1 To 5
      Load Matrix(1, 1)(L9)
  Next
End Sub

Private Sub Command2_Click()
  Dim L9&, L8&
 
  For L9 = 1 To 2
      Set Matrix(1, L9) = Me.Controls("mnu" + CStr(L9))
      For L8 = 1 To 5
          Load Matrix(1, L9)(L8)
      Next
  Next
     
End Sub
dmb - 31 Jul 2004 12:03 GMT
<snip>

>I'll look into this a bit more, but I have some other problems at
>present.

<snip>

Hi J French,

You don't have to think further for me as I found a nice and easy component at
vbAccelerator (IconMenu), which is perfect for what I want.

But still many thanks for your help until now!.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.