473,380 Members | 1,424 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,380 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 1303
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. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.