Multimobile Development: Building Applications for any Smartphone
Urgent Problem in adding Events tab to propertygrid
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.windowsforms.designtime.


gurjinder
Hi,

I am making a form designer. It is same like VS.net IDE.
I am facing difficulty in adding Eventstab to propertygrid control.
In some forums it is mentioned that just assign some Site to sIte
property of propertygrid and then just do
grid.propertytabs.addtabtype(typeof(eventstab),PropertyTabScope.Component));

but this is not working .........
can any body help.....

rgds
Gurjinder
Reply to this message...
Vote that this is a GOOD answer...
 
Really good experience at the Apple Store
MonoDroid – looking *awesome*
 
    
Paul
Hi, Gurjinder.

When I develop my design-time form, I use following code:

// There is a class to show EventTab in PropertyGrid
internal class MyPropertyGrid : System.Windows.Forms.PropertyGrid
{
private System.ComponentModel.Container components = null;
public MyPropertyGrid()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component Designer generated code
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion

public void ShowEvents(bool show)
{
ShowEventsButton(show);
}
public bool DrawFlat
{
get { return DrawFlatToolbar; }
set { DrawFlatToolbar = value; }
}
}

and add next code to your code
....
private MyPropertyGrid propertyGrid;
....
// Initialization PropertyGrid
this.propertyGrid = new MyPropertyGrid();
....
this.propertyGrid.SelectedObjectsChanged += new EventHandler(OnPropertyGridSelectedObjectChanged);
this.propertyGrid.SelectedGridItemChanged += new SelectedGridItemChangedEventHandler(OnSelectedGridItemChanged);
....
protected void OnPropertyGridSelectedObjectChanged(object sender, EventArgs e)
{
UpdatePropertyGridSite();
this.propertyGrid.ShowEvents(true);
}

private PropertyDescriptor lastProperty;
private object lastValue;
private void OnSelectedGridItemChanged(object sender, SelectedGridItemChangedEventArgs e)
{
GridItem gridItem = e.NewSelection;
if (gridItem != null && (lastProperty = gridItem.PropertyDescriptor) != null)
{
Object selectedObj = this.propertyGrid.SelectedObject;
if (selectedObj != null)
{
try
{
lastValue = lastProperty.GetValue(selectedObj);
lastProperty.AddValueChanged(selectedObj, new EventHandler(OnPropertyChanged));
}
catch {}
}
}
}
....
protected void UpdatePropertyGridSite()
{
if(propertyGrid != null)
{
propertyGrid.Site = null;
IServiceProvider provider = GetPropertyGridServiceProvider();
if(provider != null)
{
propertyGrid.Site = new MySite(provider, propertyGrid as IComponent);
propertyGrid.PropertyTabs.AddTabType(typeof(System.Windows.Forms.Design.EventsTab));
}
}
}
protected IServiceProvider GetPropertyGridServiceProvider()
{
object selObject = null;
if (propertyGrid.SelectedObjects != null && propertyGrid.SelectedObjects.Length > 0)
selObject = propertyGrid.SelectedObjects[0];
else
selObject = propertyGrid.SelectedObject;

if (selObject is Component)
return (selObject as Component).Site;

return null;
}

I hope, I help you.

If you'll have some questions, you welcome.
Reply to this message...
Vote that this is a GOOD answer...
 
First volume of Multimobile Development nearly ready to go to press
A mention on Developing for the iPhone and Android: The pros and cons
 
    
Krishnan Vijay Anand
Hi I was trying to use Your code to add the Events Tab to Property Grid. Can you send me the sample code to add the event icon on the property grid. Please do the needful.

Thanks and Regards
--------------------------------
From: Krishnan Vijay Anand
Reply to this message...
Vote that this is a GOOD answer...
 
 
 
System.ComponentModel.Container
System.ComponentModel.IComponent
System.ComponentModel.PropertyDescriptor
System.ComponentModel.PropertyTabScope
System.EventArgs
System.EventHandler
System.IServiceProvider
System.Windows.Forms.Design.EventsTab
System.Windows.Forms.GridItem
System.Windows.Forms.PropertyGrid
System.Windows.Forms.SelectedGridItemChangedEventArgs
System.Windows.Forms.SelectedGridItemChangedEventHandler




Multimobile Development: Building Applications for any Smartphone
Ad
BootFX
Reliable and powerful .NET application framework.
iOS, Android and Windows Phone Development Training and Consultancy
Hosted by RackSRV Communications
 
Multimobile Development: Building Applications for any Smartphone
Copyright © AMX Software Ltd 2008-2010. Portions copyright © Matthew Baxter-Reynolds 2001-2010. All rights reserved.
Contact Us - Terms of Use - Privacy Policy - 4.0.30129.1734