Custom property grid doesn't show collections

A

asharda

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<Object> then 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.</
summary>
public CustomPropertyGrid()
{
// Initialize
InitializeComponent();
// Create the custom validation service
m_customPropertyGridService = new
CustomPropertyGridService(this);
// Set the custom property grid to use the custom property
grid validation service
FieldInfo fieldGridView =
typeof(PropertyGrid).GetField("gridView", BindingFlags.NonPublic |
BindingFlags.Instance);
FieldInfo fieldService =
fieldGridView.FieldType.GetField("serviceProvider",
BindingFlags.NonPublic | BindingFlags.Instance);
fieldService.SetValue(fieldGridView.GetValue(this),
m_customPropertyGridService);
} // 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;
else
return base.GetService(service);
} // GetServiceInternal()
#endregion Public Methods

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

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

#region -- Constructor
/// <summary>Creates a new custom property grid service.</
summary>
/// <param name="propertyGrid">Owner</param>
public CustomPropertyGridService(CustomPropertyGrid
propertyGrid)
{
// 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.
Thanks,
 
M

Marc Gravell

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
own.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top