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 / October 2004

Tip: Looking for answers? Try searching our database.

Updating verbs in the PropertyGrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jacob - 20 Oct 2004 16:46 GMT
I'm working on a component (with a custom designer) where the designer verbs
change based on what a property is set to. The problem is,... it appears
that the designer keeps its own cache of the verbs such that when I change
the property of my component, I have to click off the component and then
back onto it to update the verb links listed in the PropertyGrid. I can't
explain it any simpler than that. If you've tried to dynamically change the
verbs before, changing the context menu verbs is easy, but changing the
links in the property grid without reselecting the component is proving to
be very difficult. Anybody have the answer?

Thanks,
Jacob

P.S. - Some sample code...

internal class MyCustomDesigner : ControlDesigner

{

public override DesignerVerbCollection Verbs

{

get

{

DesignerVerbCollection verbs = new DesignerVerbCollection();

// Adding of custom verbs here....

return verbs;

}

}

public override void Initialize(IComponent component)

{

base.Initialize(component);

// Be notified when properties are changed.

IComponentChangeService service = GetService(

typeof(IComponentChangeService)) as IComponentChangeService;

if(service != null)

service.ComponentChanged +=

new ComponentChangedEventHandler(OnComponentChanged);

}

#region Private Methods

private void OnComponentChanged(object sender, ComponentChangedEventArgs e)

{

if(e.Component == this.Component && e.Member != null && e.Member.Name ==
"Icon")

{

// This is where I want to change the verbs displayed.

}

}

}
Joey Calisay - 21 Oct 2004 03:04 GMT
you just have to have a reference of the designerverbs on the designer class
level to modify their properties on your OnComponentChanged eventhandler

public class CdxTabControlAdvancedDesigner :
System.Windows.Forms.Design.ParentControlDesigner

{

private DesignerVerb m_verbRemoveTab = null;

private DesignerVerb m_verbAddTab = null;

private void OnComponentChanged(object sender, ComponentChangedEventArgs e)

{

//Modify the designerverbs here

if (e.Component = this.Component) this.ModifyMenu();

}

protected virtual void ModifyMenu()

{

m_verbRemoveTab.Enabled = false;

if (this.CdxTabControlAdvanced.aaTabButtons.Count > 0)

{

m_verbRemoveTab.Enabled = true;

}

}

public CdxTabControlAdvancedDesigner()

{

this.m_verbAddTab = new DesignerVerb("Add Tab", new
EventHandler(this.e_OnAddTab));

this.m_verbRemoveTab = new DesignerVerb("Remove Tab", new
EventHandler(this.e_OnRemoveTab));

base.Verbs.AddRange(new DesignerVerb[] {this.m_verbAddTab,
this.m_verbRemoveTab});

}

protected override void Dispose(bool bIsDisposing)

{

IComponentChangeService cs = GetService(typeof(IComponentChangeService)) as
IComponentChangeService;

if (cs != null)

{

cs.ComponentChanged -=new ComponentChangedEventHandler(OnComponentChanged);

}

base.Dispose(bIsDisposing);

}

public override void Initialize(IComponent Icomponent)

{

base.Initialize(Icomponent);

IComponentChangeService cs = GetService(typeof(IComponentChangeService)) as
IComponentChangeService;

if (cs != null)

{

cs.ComponentChanged +=new ComponentChangedEventHandler(OnComponentChanged);

}

ModifyMenu();

}

}

> I'm working on a component (with a custom designer) where the designer verbs
> change based on what a property is set to. The problem is,... it appears
[quoted text clipped - 71 lines]
>
> }
Joey Calisay - 21 Oct 2004 03:18 GMT
I forgot to include the key thing: utilize the ISelectionService and provide
an eventhandler for its SelectionChanged.  When your control is selected,
refresh the designerverbs:

private void OnSelectionServiceSelectionChanged(object sender, EventArgs e)

{

ISelectionService ss = GetService(typeof(ISelectionService)) as
ISelectionService;

if (ss.SelectionCount == 1 && ss.PrimarySelection is CdxTabControlAdvanced)

{

this.ModifyMenu();

}

}

Added wireups on the Initialize method of the designer:

IDesignerHost host = GetService(typeof(IDesignerHost)) as IDesignerHost;

ISelectionService ss = GetService(typeof(ISelectionService)) as
ISelectionService;

if (ss != null)

{

ss.SelectionChanged +=new
EventHandler(e_OnISelectionServiceSelectionChanged);

}

sorry for the mess...
> you just have to have a reference of the designerverbs on the designer class
> level to modify their properties on your OnComponentChanged eventhandler
[quoted text clipped - 169 lines]
> >
> > }
DRaiko - 21 Oct 2004 10:23 GMT
Hello Jacob,

just my 2 cent.
A solution is described in
http://www.awprofessional.com/articles/article.asp?p=169528&seqNum=6
Section "Design-Time Context Menu Verbs". A nice text.

Close to what Joey writes (as i see it), but commented.

HTH,
Dima

> I forgot to include the key thing: utilize the ISelectionService and provide
> an eventhandler for its SelectionChanged.  When your control is selected,
[quoted text clipped - 216 lines]
> > >
> > > }
Joey Calisay - 21 Oct 2004 10:48 GMT
actually, it is one of my best reference for designers...
can't wait to buy the book, :p

> Hello Jacob,
>
[quoted text clipped - 228 lines]
> > > >
> > > > }
Jacob - 22 Oct 2004 06:50 GMT
Chris Sell's book and online chapter is no doubt a great resource. However,
I've scoured it thoroughly for a solution to my problem without an answer.
As a side note, he does present a solution to updating the verbs in the
context menu while still having the control selected using the
IMenuCommandService, but no solution for doing the same to the property
grid.

Thanks,
Jacob

> Hello Jacob,
>
[quoted text clipped - 243 lines]
>> > >
>> > > }
Jacob - 22 Oct 2004 06:47 GMT
Thank you for your great answer, but it's a solution to a little bit
different problem. I've had no problems, enabling/disabling and setting the
verbs to visible/invisible.  The problem is ADDING verbs and REMOVING verbs
from the collection. The changes made to the collection don't seem to get
updated until after the control is deselected and reselected again. I poked
around some things with Reflector and found that the PropertyGrid keeps its
own array of verbs, different from the collection that is edited in the
ControlDesigner. That seems to be the problem. The PropertyGrid's array
doesn't get updated when a property is changed on the control and the
control is still selected until after you deselect it and reselect it again.
Do you have an answer for this one?

Jacob

P.S. - I've tried using the ISelectionService to deselect all controls and
reselect my control after the control's property is changed but it still
won't update the PropertyGrids verbs unless you deselect and reselect
yourself.

>I forgot to include the key thing: utilize the ISelectionService and
>provide
[quoted text clipped - 223 lines]
>> >
>> > }
Jer_m - 26 Oct 2004 03:51 GMT
Hi Jacob,

I had the same problem, maybe someone else can shed some light on
this....

in the meantime, I have been able to get ISelectionService to work.
Is this how your doing it?

DesignerVerb verbTestOn;
DesignerVerb verbTestOff;

public override initialize(IComponent component)
{
   verbTestOn = new DesignerVerb("Test On",new EventHandler(TestOn));
   verbTestOff = new DesignerVerb("Test Off",new
EventHandler(TestOff));

   Verbs.Add(verbTestOn);
}

private void TestOn(object sender, EventArgs e)
{
   Verbs.Remove(verbTestOn);
   Verbs.Add(verbTestOff);

   ISelectionService ss =
(ISelectionService)GetService(typeof(ISelectionService));

   ss.SetSelectedComponents(new IComponent[] { this.Control.Parent }
);
   ss.SetSelectedComponents(new IComponent[] { this.Control } );
}

private void TestOff(object sender, EventArgs e)
{
   Verbs.Add(verbTestOn);
   Verbs.Remove(verbTestOff);

   ISelectionService ss =
(ISelectionService)GetService(typeof(ISelectionService));

   ss.SetSelectedComponents(new IComponent[] { this.Control.Parent }
);
   ss.SetSelectedComponents(new IComponent[] { this.Control } );
}

kind regards
Jerron

> Thank you for your great answer, but it's a solution to a little bit
> different problem. I've had no problems, enabling/disabling and setting the
[quoted text clipped - 242 lines]
> >> >
> >> > }
Jacob - 28 Oct 2004 06:29 GMT
Thanks for the suggestion but I've tried the ISelectionService approach that
you suggested. It works in your instance where it's a verb that is being
invoked, but not in my instance where a property is changing in the property
grid. Amazingly doing the exact same thing that you've suggested here won't
work if you put it in a IComponentChanged event handler.

Jacob

> Hi Jacob,
>
[quoted text clipped - 309 lines]
>> >> >
>> >> > }

Rate this thread:







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.