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 2005

Tip: Looking for answers? Try searching our database.

Component Creation/Deletion bound to PropertyChange Problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
joeycalisay - 23 Feb 2005 07:21 GMT
I have a custom enum property Parts for my custom containercontrol declared
as below:

[Flags]
public enum Parts : int
{
  None = 0,
  Header = 1,
  HeaderDetail = 3,
  HeaderFooter = 5,
  HeaderDetailFooter = 7
}

Depending on the Parts configuration chosen at designtime, I will be
creating/destroying the associated components (Header, Detail or Footer). As
such, I am just attaching a custom eventhandler on the property set method
since it is logical that the whole implementation is associated with the
property change.

The problem is with regard to the undo/redo feature of VS. For example, when
I changed from HeaderFooter to Header, the Footer component is removed from
my custom containercontrol and destroyed from the form surface through the
designerhost after the property set. When I Redo the property change, VS
tries to recreate the destroyed component since it was part of the property
change transaction then after that comes the property change which has my
handler to create a Footer component and then add it to my containercontrol.
The additional component gets created in the form and gets code gen'ed which
basically has no function since it was not added to any control collection.

I need some views perhaps there is wrong with my design. Is it possible to
have a check in the end so I can destroy again the dummy components created
by undo? But then this will be costly and not ideal. Or perhaps I just
disable the undo/redo feature for the said property change? Please help...

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

azerty - 23 Feb 2005 22:13 GMT
I am not sure if this point can help your (i don't understand very well your
scenariio)

but When you want create or destroy a component in design mode you must use
the IDesignerHost.CreateComponent or IDesignerHost.DestroyComponent method.

example of code :

 protected override DataGridItemExtenderBase NewItem(DataGrid dataGrid,
DataGridItemExtenderBase item)
 {
  DataGridColumnExtender result;
#if DESIGN
  System.ComponentModel.Design.IDesignerHost dh =
dataGrid.GetDesignerHost();
  if (dh != null)
  {
   result =
(DataGridColumnExtender)dh.CreateComponent(typeof(DataGridColumnExtender));
   result.MappingName = item.MappingName;
  }
  else
#endif
   result = new DataGridColumnExtender((DataGridColumnExtender)item);

  return result;

> I have a custom enum property Parts for my custom containercontrol declared
> as below:
[quoted text clipped - 29 lines]
> by undo? But then this will be costly and not ideal. Or perhaps I just
> disable the undo/redo feature for the said property change? Please help...
joeycalisay - 24 Feb 2005 05:19 GMT
Thanks a lot for the reply azerty but I am well aware of the said method and
I referred to it in my post as "creation through the designerhost".

Signature

Joey Calisay
http://spaces.msn.com/members/joeycalisay/

> I am not sure if this point can help your (i don't understand very well your
> scenariio)
[quoted text clipped - 14 lines]
>    {
>     result =

(DataGridColumnExtender)dh.CreateComponent(typeof(DataGridColumnExtender));
>     result.MappingName = item.MappingName;
>    }
[quoted text clipped - 46 lines]
> > by undo? But then this will be costly and not ideal. Or perhaps I just
> > disable the undo/redo feature for the said property change? Please help...
Frank Hileman - 24 Feb 2005 13:39 GMT
Hello Joey,

I don't think it is a good idea to use a property set event handler this
way. Typically, you would either "shadow" the property in a custom designer
(PreFilterProperties, etc) or subscribe to the ComponentChanged event
(IComponentChangeService). It could be that if  you use this instead, you
will be rid of the problem. But I don't think so.

A more fundamental question is how to handle dependent properties in
general. A dependent property is modified when another property is modified.
If the dependent property is not serialized, there is no problem.

In your case, it is not a dependent property, but a dependent component
creation. Because it is a component known to the root designer, it must be
recorded in the designer transaction. And it is serialized. Essentially it
is a similar problem to dependent properties.

I am not sure of the best solution, but you may want to either prevent
serialization of the parts configuration, or make the footer component not
an IComponent, but simply a property in another object. In either case, one
change (parts) or the other (footer) must not be recorded in the designer
transaction, so you don't get a "double change" on playback. When you use
dependent properties, only a single property change should be recorded.

Regards,
Frank Hileman

check out VG.net: http://www.vgdotnet.com
Animated vector graphics system
Integrated Visual Studio .NET graphics editor

>I have a custom enum property Parts for my custom containercontrol declared
> as below:
[quoted text clipped - 37 lines]
> by undo? But then this will be costly and not ideal. Or perhaps I just
> disable the undo/redo feature for the said property change? Please help...

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.