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 / April 2007

Tip: Looking for answers? Try searching our database.

Urgent Problem  in adding Events tab to propertygrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
gurjinder - 29 Jul 2004 08:21 GMT
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
Paul - 03 Aug 2004 11:09 GMT
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
David - 14 Jan 2005 12:22 GMT
Hi Paul,

Your code seems really helpful but i can't implement it to fit my needs. Some errors appears due to absence of MySite (i have my implementation) and OnPropertyChanged().

Can you explain how to integrate your code in a DesignerHost control. I think that's what you did for yourself.

Thanks in advance.

David
palaniselvam - 02 Apr 2007 23:17 GMT
Hi Paul,

I have used your code for my custom control to show-up Events Tab section. But it is not showing the events tab at all.  I also referred the following link ..I am not able to find out solution. My requirement is i have custom control conains a property . This property contains collection of Object. Class for this object contains an event. This particular event is not showing up in design time.

I also referred the following link ; but for me it is not working:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=438792&SiteID=

From http://www.developmentnow.com/g/32_2004_7_0_0_123537/Urgent-Problem-in-adding-Ev
ents-tab-to-propertygrid.ht


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.