Hi Steve,
Thank you for posting.
Do you mean that you want to place a "CheckedListBox" property within a
PropertyGrid in your own program?
If so, I think you should inherite a class from DesignSurface, add a
reference to ISelectionService instance in it and handle the
ISelectionService instance's SeletionChanged event.
Then you could add a CheckedListBox control and a PropertyGrid control on a
form in code. When the program is running, a CheckedListBox control appears
on the form. After you select the CheckedListBox on the form, its property
will be shown in the PropertyGrid.
Below is the sample code.
=====================================HostSurface.c s=========================
=============
using System;
using System.Collections;
using System.ComponentModel.Design;
using System.Windows.Forms;
public class HostSurface : DesignSurface
{
private ISelectionService _selectionService;
public HostSurface() : base()
{
// Set SelectionService - SelectionChanged event handler
_selectionService =
(ISelectionService)(this.ServiceContainer.GetServi ce(typeof(ISelectionServic
e)));
_selectionService.SelectionChanged += new
EventHandler(selectionService_SelectionChanged);
}
// When the selection changes this sets the PropertyGrid's selected
component
private void selectionService_SelectionChanged(object sender,
EventArgs e)
{
if (_selectionService != null)
{
ICollection selectedComponents =
_selectionService.GetSelectedComponents();
PropertyGrid propertyGrid =
(PropertyGrid)this.GetService(typeof(PropertyGrid) );
if (propertyGrid != null)
{
object[] comps = new object[selectedComponents.Count];
int i = 0;
foreach (Object o in selectedComponents)
{
comps[i] = o;
i++;
}
propertyGrid.SelectedObjects = comps;
}
}
}
public void AddService(Type type, object serviceInstance)
{
this.ServiceContainer.AddService(type, serviceInstance);
}
}
================================================== ==========================
==========
=====================================Form1.cs===== ==========================
==========
using System.ComponentModel.Design;
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
HostSurface surface = new HostSurface();
surface.BeginLoad(typeof(Form));
Control view = (Control)surface.View;
view.Dock = DockStyle.Fill;
view.Parent = this;
surface.AddService(typeof(PropertyGrid), this.propertyGrid1);
// add a checkedlistbox onto the form designer
IDesignerHost idh =
(IDesignerHost)surface.GetService(typeof(IDesigner Host));
IToolboxUser tbu = idh.GetDesigner(idh.RootComponent as
IComponent) as IToolboxUser;
if (tbu != null)
{
ToolboxItem toolboxitem = new
ToolboxItem(typeof(CheckedListBox));
tbu.ToolPicked((System.Drawing.Design.ToolboxItem) toolboxitem);
}
}
}
================================================== ==========================
For more information on DesignSurface, you may refer to the following link:
http://msdn.microsoft.com/msdnmag/is...g/default.aspx
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.