471,624 Members | 2,133 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,624 software developers and data experts.

Custom property grid doesn't show collections

I have a custom property grid. I am using custom property grid as I do
not want the error messages that the propertygrid shows when abphabets
are entered in interger fields.

The custom property grid doesn't show colloections i.e. if I have a
List<Objectthen the Collection is shown but when I click on the
"..." button next to it nothing comes up.

If I say CustomPropertyGrid p = new CustomPropertyGrid();
p.SelectedObject = new ComboBox();

Notice that if the "..." button after the collection is clicked
nothing comes up.
Can someone please help.
Here is the custom property grid

using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Reflection;
using System.Collections;

namespace TestPropertyGrid
public partial class CustomPropertyGrid : PropertyGrid
#region -- Members
private CustomPropertyGridService m_customPropertyGridService
= null; // Custom Property Grid Service
#endregion Members

#region -- Constructor
/// <summary>Creates the custom property grid component.</
public CustomPropertyGrid()
// Initialize
// Create the custom validation service
m_customPropertyGridService = new
// Set the custom property grid to use the custom property
grid validation service
FieldInfo fieldGridView =
typeof(PropertyGrid).GetField("gridView", BindingFlags.NonPublic |
FieldInfo fieldService =
fieldGridView.FieldType.GetField("serviceProvider" ,
BindingFlags.NonPublic | BindingFlags.Instance);
fieldService.SetValue(fieldGridView.GetValue(this) ,
} // CustomPropertyGrid()
#endregion Constructor

#region -- Public Methods
/// <summary>Gets the custom property grid service.</summary>
public object GetServiceInternal(Type service)
// Return custom service in place of internal service
if (service == typeof(IUIService))
return m_customPropertyGridService;
return base.GetService(service);
} // GetServiceInternal()
#endregion Public Methods

#region -- Overrides
/// <summary>Returns a custom property grid validation
protected override object GetService(Type service)
// Return the custom property grid service in place of the
return GetServiceInternal(service);
} // GetService()
#endregion Overrides
} // Custom Property Grid

public class CustomPropertyGridService : IServiceProvider,
#region -- Members
private CustomPropertyGrid m_propertyGrid = null; // Service
#endregion Members

#region -- Constructor
/// <summary>Creates a new custom property grid service.</
/// <param name="propertyGrid">Owner</param>
public CustomPropertyGridService(CustomPropertyGrid
// Set the owner
m_propertyGrid = propertyGrid;
} // CustomPropertyGridService()
#endregion Constructor

#region -- IServiceProvider Implementation
/// <summary>Gets the custom property grid service.</summary>
public object GetService(Type service)
// Return the custom property grid's service
return m_propertyGrid.GetServiceInternal(service);
} // GetService()
#endregion IServiceProvider Implementation

#region -- IUIService Implementation
/// <summary>Shows a custom error dialog in place of the
internal service's error dialog.</summary>
public DialogResult ShowDialog(Form form)
// Cancel invalid value
return DialogResult.Cancel;
} // ShowDialog()

public IDictionary Styles { get { return null; } }

public bool CanShowComponentEditor(object component) { return
true; }

public IWin32Window GetDialogOwnerWindow() { return null; }

public void SetUIDirty() { }

public bool ShowComponentEditor(object component, IWin32Window
parent) { return true; }

public void ShowMessage(string message) { }

public void ShowMessage(string message, string caption) { }

public DialogResult ShowMessage(string message, string
caption, MessageBoxButtons buttons) { return DialogResult.OK; }

public bool ShowToolWindow(Guid toolWindow) { return false; }

public void ShowError(string message) { }

public void ShowError(Exception ex) { }

public void ShowError(Exception ex, string message) { }
#endregion IUIService Implementation
} // Custom Property Grid Service

Any help will be appreciated.
Aug 22 '08 #1
1 4184
That code is a: incomplete, and b: too long to really answer. In
particular, it doesn't show anything relating to the collection
handling (nor UITypeEditor, etc).

Writing a PropertyGrid is not trivial; there are a few available (some
free, some to buy) that might be a better option than writing your

Aug 23 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Altman | last post: by
6 posts views Thread by tshad | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.