471,315 Members | 2,108 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,315 software developers and data experts.

Delegate Implementation Questions

I hope I can explain this in a way that can be understood.

I have a custom control, I'll call it navigator, used to navigate
"things". I has, among other controls, two standard buttons, previous
and next. This control is implemented by other custom controls that
displays "things" in different ways. What happens when the previous
or next buttons are clicked depends on the type of parent control. To
me, this seems like a classic delegate scenario. What I'm struggling
with is the proper way to tell the navigator control which method to
use (each parent control has a method that calculates what previous or
next actually are).

What I'd like to do is create and assign the delegate inside the
navigator control with something like this:

delegate NextDelegate = new delegate(this.parent.NextThing);

This fails to compile, as the compiler has no clue how to find
"NextThing". I can deal with that.

My first inclination is to create public properties in the navigator
control and set those properties from the parent to the desired
methods when the navigator control is instantiated.

My second is to have the parent subscribe to the click event on the
navigator control buttons and handle the entire process from the
parent control. But, this forces me to put code common to all
instances of the navigator control in each parent control the
implements the navigator control (a lot of duplicate code).

The more I think about it, the more I like the first method. But,
something tells me there is some type of slick casting/typeof method
that might allow me to implement this as above. I'm interested in
other options and opinions.

Thanks,

Greg
Dec 6 '05 #1
1 1221
Greg,

What I would have is an event, "Navigating", with a specific event args
instance "NavigatingEventArgs". This event args class would expose the
address of the current thing being shown (something to uniquely identify
what is being shown), as well as the direction (forward or back, or first or
last, if you want to add those things), and the address of what the next
item should be (it would be able to be set, so the event handler could
change it).

Then, when your forward and back buttons are clicked, you fire the
event. Your parent control would then find out what to show, and show it,
or change what should be shown (you would have to handle when new entries
are added, etc, etc).

It shouldn't be too hard really. You could also expose a method which
will take an identifier and you can move to that location in the stack.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Greg Wilkerson" <gr***********@charter.net> wrote in message
news:4u********************************@4ax.com...
I hope I can explain this in a way that can be understood.

I have a custom control, I'll call it navigator, used to navigate
"things". I has, among other controls, two standard buttons, previous
and next. This control is implemented by other custom controls that
displays "things" in different ways. What happens when the previous
or next buttons are clicked depends on the type of parent control. To
me, this seems like a classic delegate scenario. What I'm struggling
with is the proper way to tell the navigator control which method to
use (each parent control has a method that calculates what previous or
next actually are).

What I'd like to do is create and assign the delegate inside the
navigator control with something like this:

delegate NextDelegate = new delegate(this.parent.NextThing);

This fails to compile, as the compiler has no clue how to find
"NextThing". I can deal with that.

My first inclination is to create public properties in the navigator
control and set those properties from the parent to the desired
methods when the navigator control is instantiated.

My second is to have the parent subscribe to the click event on the
navigator control buttons and handle the entire process from the
parent control. But, this forces me to put code common to all
instances of the navigator control in each parent control the
implements the navigator control (a lot of duplicate code).

The more I think about it, the more I like the first method. But,
something tells me there is some type of slick casting/typeof method
that might allow me to implement this as above. I'm interested in
other options and opinions.

Thanks,

Greg

Dec 6 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Jeff S | last post: by
7 posts views Thread by Ant | last post: by
11 posts views Thread by ohmmega | last post: by
9 posts views Thread by Bob Altman | last post: by
10 posts views Thread by vcquestions | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.