Home All Groups Group Topic Archive Search About

Dynamic controls, menuitems, windowlist

Author
3 Feb 2006 3:39 PM
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

Author
3 Feb 2006 3:49 PM
Larry Lard
YYZ wrote:
Show quoteHide quote
> 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.

--
Larry Lard
Replies to group please
Author
3 Feb 2006 3:54 PM
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
Author
3 Feb 2006 3:52 PM
Armin Zingler
Show quote Hide quote
"YYZ" <matt.da***@gmail.com> schrieb
> 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
Author
3 Feb 2006 4:04 PM
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
Author
3 Feb 2006 5:36 PM
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
Author
3 Feb 2006 5:40 PM
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