Dynamic controls, menuitems, windowlist

Y

YYZ

In my program, a user can open up many different "Loans" -- each one is
loaded into a dynamically created usercontrol (ucLoan) -- in order for
them to be able to switch between the ones they have open, I have added
a Window menu item -- just like in Word or any one of a thousand
different applications.

Each Loan has a unique GUID, and I could easily enumerate all of the
ucLoan controls on the main form and check their GUID property to find
the one that I want...however, the MenuItem object doesn't seem to have
a property I can use to store this guid...no tag, etc. Am I missing
something?

Assuming that that is true, how would any of you go about doing this?
What I really need is a way to associate a menu item with a certain
control on my form -- dynamically, of course. The text of the menu
item needs to be understandable by my users, so I don't want to put a
GUID in the text.

Matt
 
L

Larry Lard

YYZ said:
In my program, a user can open up many different "Loans" -- each one is
loaded into a dynamically created usercontrol (ucLoan) -- in order for
them to be able to switch between the ones they have open, I have added
a Window menu item -- just like in Word or any one of a thousand
different applications.

Each Loan has a unique GUID, and I could easily enumerate all of the
ucLoan controls on the main form and check their GUID property to find
the one that I want...however, the MenuItem object doesn't seem to have
a property I can use to store this guid...no tag, etc. Am I missing
something?

Assuming that that is true, how would any of you go about doing this?
What I really need is a way to associate a menu item with a certain
control on my form -- dynamically, of course. The text of the menu
item needs to be understandable by my users, so I don't want to put a
GUID in the text.

Create your own class derived from MenuItem, then you can

a) put in it whatever properties etc you like, eg associated user
control, GUID, whatever
b) since it is derived from MenuItem, it _is_ still a MenuItem, so you
can put it in menus as normal.
 
A

Armin Zingler

YYZ said:
In my program, a user can open up many different "Loans" -- each one
is loaded into a dynamically created usercontrol (ucLoan) -- in
order for them to be able to switch between the ones they have open,
I have added a Window menu item -- just like in Word or any one of a
thousand different applications.

Each Loan has a unique GUID, and I could easily enumerate all of the
ucLoan controls on the main form and check their GUID property to
find the one that I want...however, the MenuItem object doesn't seem
to have a property I can use to store this guid...no tag, etc. Am I
missing something?

Assuming that that is true, how would any of you go about doing
this? What I really need is a way to associate a menu item with a
certain control on my form -- dynamically, of course. The text of
the menu item needs to be understandable by my users, so I don't
want to put a GUID in the text.


Write a class inheriting from MenuItem and add a property referencing the
Loan object or the ucLoan control. If it references the Loan object - what I
would prefer - keep all ucLoan controls in a Hashtable and use the GUID as
the key. If a menu item is clicked, you have the Loan object, it's GUID and
can retrieve the ucLoan object from the Hashtable.


Armin
 
Y

YYZ

Create your own class derived from MenuItem, then you can

Okay, I admit I'm new to .Net, but holy crap, of COURSE that's what I
should do. Thanks for pointing out so quickly what an idiot I am. <g>

Seriously, thanks -- I can't believe I didn't think of that one on my
own!

Matt
 
Y

YYZ

Write a class inheriting from MenuItem and add a property referencing the
Loan object or the ucLoan control. If it references the Loan object - what I
would prefer - keep all ucLoan controls in a Hashtable and use the GUID as
the key. If a menu item is clicked, you have the Loan object, it's GUID and
can retrieve the ucLoan object from the Hashtable.

Even better -- no need to enumerate the controls collection looking for
Loan objects.

Thanks Armin and Larry.

Matt
 
Y

YYZ

Write a class inheriting from MenuItem and add a property referencing the
Loan object or the ucLoan control. If it references the Loan object - what I
would prefer - keep all ucLoan controls in a Hashtable and use the GUID as
the key. If a menu item is clicked, you have the Loan object, it's GUID and
can retrieve the ucLoan object from the Hashtable.

Okay, I think I'm missing something. When adding a menuitem to a menu,
I have 5 methods to choose from. I think I need a hybrid of 2 of them.
One allows you to add a menuitem by passing an existing menuitem. I
need this to pass my own inherited menuitem class (an actual
instance)...however I also need to have an event handler, too. Which I
can't do with the built-in add menuitem methods.

How do I assign an event handler to an object at run time? I tried
searching on this, but I think I don't know the terms to search
for...any pointers?

Thanks.

Matt
 
Y

YYZ

Okay, I'm very sorry. It helps when you spell eventhandler correcly.
Here is what I'm doing:

dim oTest as clsMenuItem
oTest = new clsMenuItem
oTest.LoanGuid = sGuid
oTest.Text = "Testing" & sGuid
mnuWindow.MenuItems.Add(oTest)

AddHandler oTest.Click, AddressOf WinListClick

Haven't tested it yet, but I wanted to short-circuit anyone who might
answer with the obvious solution.

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top