473,396 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 1304
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Sharon | last post by:
I’m trying to build a generic Publisher-Subscriber that will work over the net, so I’m using the Remoting. I wish that the subscriber user will be notify about the messages sent by the...
3
by: Jeff S | last post by:
Please consider this sample code: It registers a delegate with an event. p1.FirstNameChanged += new Person.NameChanged(p1_FirstNameChanged); Now the following code removes the delegate:...
7
by: Ant | last post by:
Hello, Very simple question but one I need clarified. Which part of the statement below is considered the 'delegate'? Is it the 'new System.EventHandler' or the btnAccept_Click? or is it...
5
by: atwomey | last post by:
When I try and place a delegate in an interface, like this : public interface ITest { double foo(); delegate void bar(); } I get an error "delegates cannot declare types". What is it about a...
4
by: Bill Woodruff | last post by:
< note : this message was sparked in part by comments by David Browne on a previous thread : "inserting an anonymous method as a value in a generic dictionary ?" : David had shown the use of...
11
by: ohmmega | last post by:
hello world. i would like to implement a class with a timer, witch informs me every second about it's tick. the code works already, but i would like to change a thing (or more). <code> //at...
7
by: Dave | last post by:
I've got these declarations: public delegate void FormDisplayResultsDelegate<Type>(Type displayResultsValue); public FormDisplayResultsDelegate<stringdisplayMsgDelegate; instantiation:...
9
by: Bob Altman | last post by:
I'm trying to call a function on a background thread in a C++/CLI (VS 2005) application compiled with /clr. I store a delegate reference in a module-level gcroot. When I call BeginInvoke on the...
10
by: vcquestions | last post by:
Hi. Is there way to have a function pointer to a delegate in c++/cli that would allow me to pass delegates with the same signatures as parameters to a method? I'm working with managed code. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.