Hi M_Moghrabbi,
Have a look at this runnable example:
Hard to tell from your description if this is exactly what you want - but I think it's quite close:
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace PropertyGridTest
{
static class Program
{
class TestPropertyEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService editorservice = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorservice != null)
{
Form formDialog = new Form();
Button buttonOk = new Button { Text = "Ok", Dock = DockStyle.Bottom, DialogResult = System.Windows.Forms.DialogResult.OK, Parent = formDialog };
Button buttonCancel = new Button { Text = "Cancel", Dock = DockStyle.Bottom, DialogResult = System.Windows.Forms.DialogResult.Cancel, Parent = formDialog };
formDialog.CancelButton = buttonCancel;
formDialog.AcceptButton = buttonOk;
ListBox listbox = new ListBox { Dock = DockStyle.Fill, Parent = formDialog };
listbox.Items.AddRange(new object[] { "Test1", "Test2", "Test3" });
if (value != null)
listbox.SelectedItem = value;
if (editorservice.ShowDialog(formDialog) == DialogResult.OK)
{
value = listbox.SelectedItem;
}
}
return value;
}
}
class TestObject
{
[Editor(typeof(TestPropertyEditor), typeof(UITypeEditor))]
public string TestProperty { get; set; }
}
static void Main()
{
Form formMain = new Form();
PropertyGrid pg = new PropertyGrid { Dock = DockStyle.Fill, Parent = formMain };
pg.SelectedObject = new TestObject();
Application.Run(formMain);
}
}
}
So I created a
TestObject
class representing the object type you show on your PropertyGrid. This class has one string property
TestProperty
- this represents the "TextBox" value in your PropertyGrid - but we set the
Editor
Attribute to our own editor (
TestPropertyEditor
). If you click on the button next to the (initally empty) property value, the dialog defined inside our Editor implementation will open and show a selection.
Does this code what you want? - if not feel free to ask for further help...
Kind regards
Johannes