Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
DotNet
acad.assignment.mngr
academic
adonet
aspnet
aspnet.announcements
aspnet.build.controls
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
clr
compactframework
component_services
datatools
distributed_apps
drawing
faqs
framework
framework.wmi
general
internationalization
interop
languages.csharp
languages.jscript
languages.vb
languages.vb.controls
languages.vb.data
languages.vb.upgrade
languages.vc
languages.vc.libraries
myservices
odbcnet
performance
remoting
scripting
sdk
security
setup
vjsharp
vsa
webservi.enhancements
webservices
windowsforms
windowsforms.controls
winforms.databinding
winforms.designtime
xml
  
 
date: Thu, 23 Feb 2006 13:54:11 -0500,    group: microsoft.public.dotnet.framework.windowsforms.designtime        back       


Notify when collection changes   
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?
date: Thu, 23 Feb 2006 13:54:11 -0500   author:   Greg am

Re: Notify when collection changes   
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)

{

}

}



"Greg" <gdog@nospam.nospam> wrote in message 
news:%23fDxWrKOGHA.2828@TK2MSFTNGP12.phx.gbl...
>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?
>
date: Fri, 24 Feb 2006 00:41:15 -0500   author:   Michael Gunter

Re: Notify when collection changes   
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))]

-- 
Regards,
Inna Stetsyak aka InK_

"Greg" <gdog@nospam.nospam> wrote in message
news:%23fDxWrKOGHA.2828@TK2MSFTNGP12.phx.gbl...
> 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?
>
>
date: Tue, 28 Feb 2006 10:36:26 +0200   author:   InK_

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us