472,805 Members | 3,554 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

PropertyGrid and CheckedListBox

Can someone show me an example of how to place a "CheckedListBox" property
within a PropertyGrid?
--
-----------
Thanks,
Steve
Jul 20 '06 #1
6 6848
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.

Jul 21 '06 #2
Please accept my appology for not being more clear. I have a PropertyGrid in
a form.

I want to dynamically read values from a file and create a checkedlistbox
from that list.

I want to place in my propertygrid a property that will, when selected,
display a CheckedListBox with the values read from the file. I then wish to
check the appropriate values in the list and have those returned to my
PropertyGrid property for later processing. Is this more clear?

--
-----------
Thanks,
Steve
"Linda Liu [MSFT]" wrote:
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.

Jul 21 '06 #3
Hi Steve,

Thank you for your quickly response.

I am sorry that I may not understand your meaning.
>I want to dynamically read values from a file and create a checkedlistbox
from that list.
Do you mean that you want to initialize the items of the CheckedListBox
with the value in the file?
>I want to place in my propertygrid a property that will, when selected,
display a CheckedListBox with the values read from the file.
Do you mean that you want to display the property of the CheckedListBox in
the PropertyGrid at run time?

If I'm off base, please feel free to tell me.

I think you could place a CheckedListBox and a PropertyGrid controls on
your form. In the form's Load event handler, you may initialize the items
of the CheckedListBox and then set this CheckedListBox to the
SelectedObject property of the PropertyGrid to display the properties of
the CheckedListBox in the ProportyGrid.

The sample code is like below.
private void Form1_Load(object sender, EventArgs e)
{
// I add items to the CheckedListBox directly here. You may replace
it with your actual code
this.checkedListBox1.Items.Add("1");
this.checkedListBox1.Items.Add("2");
this.propertyGrid1.SelectedObject = this.checkedListBox1;
}

Hope this helps.
Sincerely,
Linda Liu
Microsoft Online Community Support
Jul 21 '06 #4
Hi Steve,

I am closely monitoring the newsgroup and I am contacting you to check the
issue status.

If the problem is not resolved or you have anything unclear, please feel
free to post in the newsgroup and we will follow up.

Thank you for using our MSDN Managed Newsgroup Support Service!
Sincerely,
Linda Liu
Microsoft Online Community Support
Jul 25 '06 #5
I was able to come up with a solution. Sorry for not letting you know sooner.
--
-----------
Thanks,
Steve
"Linda Liu [MSFT]" wrote:
Hi Steve,

I am closely monitoring the newsgroup and I am contacting you to check the
issue status.

If the problem is not resolved or you have anything unclear, please feel
free to post in the newsgroup and we will follow up.

Thank you for using our MSDN Managed Newsgroup Support Service!
Sincerely,
Linda Liu
Microsoft Online Community Support
Jul 25 '06 #6
Hi Steve,

Thank you for your response. I am very glad to hear that you have solved
the problem.

If you have any other questions in the future, please don't hesitate to
contact us. It's always our pleasure to be of assistance.
Sincerely,
Linda Liu
Microsoft Online Community Support
Jul 26 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Matt C. | last post by:
Does the CheckedListBox support DisplayMember/ValueMember? I have been trying to use these properties with the CheckedListBox and they are not working. I see from Google that databinding is not...
4
by: Reza | last post by:
Hi, I want to check one of the memebrs of a checkedListbox based on its value. I 'm getting a number(say 1355) from another control and based on that number I want to check an item which its...
4
by: Matthew | last post by:
Hi, I am using a checkedlistbox on a windows form and binding it to a collection of classes. clbAliases is the checkedlistbox control selectedplace is a class with property placealiases.This...
7
by: siddhiash | last post by:
Hi Friends I want to add PasswordChar Property which shows ****** for string which I type in PropertyGrid Control. Regards, Siddharth
8
by: Derek Martin | last post by:
Here is some code that I need help with please: Dim result As New ArrayList Try For i = 0 To objecttest1.PersonList.person_returnnumber - 1 result =...
2
by: Manuel Canas | last post by:
Hi there, I'm having this dilema with a checkedlistbox. I have an array of items in there, what I want to accomplish is the following; The user could check all the items in the...
0
by: Terry Olsen | last post by:
Dim dirs() as string = Directory.GetDirectories(MyPath) CheckedListBox.DataSource = dirs CheckedListBox.Update For I as Integer = 0 To CheckedListBox.Items.Count - 1...
5
by: mabond | last post by:
Hi Can't believe I've not been able to find the answer to this in the on-line help. I have a CheckedListBox which, via a timer control, is populated with the names of files in a network...
4
by: phcmi | last post by:
I have a PropertyGrid question. My task is to replace a legacy dialog box presentation with a modern one. The dialog itself allows the user to set configuration settings in our application, so...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.