Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / February 2006

Tip: Looking for answers? Try searching our database.

Notify when collection changes

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg - 23 Feb 2006 18:54 GMT
I have a control derived from UserControl with a collection member.  When
the designer invokes its collection editor and the developer adds/removes
items, can I get notified of that in my control?  When they hit OK on the
collection editor dialog, I'd like to invoke some of my code.  How do I do
that?
Michael Gunter - 24 Feb 2006 05:41 GMT
Depending on your intent, you may need to implement a custom designer. If
your collection is of classes inherited from Components, it's quite easy.
All you have to do is catch the ComponentRemoving/ComponentRemoved events
from IComponentChangeService. Here's some code I have lying around.

public class DteAddInDesigner : ComponentDocumentDesigner

{

private DteAddIn _addIn;

protected override void Dispose(bool disposing)

{

if (disposing)

{

IComponentChangeService c = (IComponentChangeService)
GetService(typeof(IComponentChangeService));

c.ComponentAdded -= new ComponentEventHandler(OnComponentAdded);

c.ComponentRemoving -= new ComponentEventHandler(OnComponentRemoving);

c.ComponentRename -= new ComponentRenameEventHandler(OnComponentRename);

}

base.Dispose(disposing);

}

public override void Initialize(System.ComponentModel.IComponent component)

{

base.Initialize(component);

// Record instance of control we're designing

_addIn = (DteAddIn) component;

// Hook up events

IComponentChangeService c = (IComponentChangeService)
GetService(typeof(IComponentChangeService));

c.ComponentAdded += new ComponentEventHandler(OnComponentAdded);

c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);

c.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);

}

public override void OnSetComponentDefaults()

{

_addIn.Text = _addIn.Site.Name;

base.OnSetComponentDefaults ();

}

private void OnComponentAdded(object sender, ComponentEventArgs e)

{

}

private void OnComponentRemoving(object sender, ComponentEventArgs e)

{

}

private void OnComponentRename(object sender, ComponentRenameEventArgs e)

{

}

}

>I have a control derived from UserControl with a collection member.  When
>the designer invokes its collection editor and the developer adds/removes
>items, can I get notified of that in my control?  When they hit OK on the
>collection editor dialog, I'd like to invoke some of my code.  How do I do
>that?
InK_ - 28 Feb 2006 08:36 GMT
Greg

You can do it also in the following way:

1. You can impelement your collection derived from CollectionBase.

2. Impelement your CollectionEditor.
It can override e.g. CreateInstance and DestroyInstance methods.They will
give you possibility to control additions and removals.
You could store your control in your CollectionEditor so that you'd be able
to call any control methods on addition and remove.

3. Add an attribute to your custom collection
[Editor(typeof(MyCollectionEditor),
typeof(System.Drawing.Design.UITypeEditor))]

Signature

Regards,
Inna Stetsyak aka InK_

> I have a control derived from UserControl with a collection member.  When
> the designer invokes its collection editor and the developer adds/removes
> items, can I get notified of that in my control?  When they hit OK on the
> collection editor dialog, I'd like to invoke some of my code.  How do I do
> that?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.