473,574 Members | 2,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PropertyGrid - how to display a string array as dropdown property


I am using a property grid to display a classes properties, all is OK for
single value properties but i need to display a list of strings for the user
to select from and update the property value based on the selection.
A Drop down list in the property grid would be ideal.
For instance - like the StartPosition property of a form in the IDE.

I think this would be a simple and often used procedure but i have not been
able to locate an example of the code required, can anyone advise?

Dec 15 '06 #1
4 35921
Normally this would be done via the type-converter of the property-type
(string in this case), which you obviously can't change in this
scenario. You could encapsulate the string into a simple class, and set
the converter for that, otherwise just set the converter for the
property:

using System;
using System.Componen tModel;
using System.Windows. Forms;
public class MyTest
{
private int test1;
public int Test1
{
get { return test1; }
set { test1 = value; }
}
private string test2;
[TypeConverter(t ypeof(StringLis tConverter))]
public string Test2
{
get { return test2; }
set { test2 = value; }
}
}
public class StringListConve rter : TypeConverter
{
public override bool
GetStandardValu esSupported(ITy peDescriptorCon text context)
{
return true; // display drop
}
public override bool
GetStandardValu esExclusive(ITy peDescriptorCon text context)
{
return true; // drop-down vs combo
}
public override StandardValuesC ollection
GetStandardValu es(ITypeDescrip torContext context)
{
// note you can also look at context etc to build list
return new StandardValuesC ollection(new string[] { "abc",
"def", "ghi" });
}
}
class Program
{
static void Main()
{
using (Form f = new Form())
using(PropertyG rid pg = new PropertyGrid())
{
pg.Dock = DockStyle.Fill;
pg.SelectedObje ct = new MyTest();
f.Controls.Add( pg);
Application.Run (f);
}
}
}

Dec 15 '06 #2

Thanks, works fine, I would like to extend my use of the Property grid
to include objects within objects that would also be viewable/updateable
within the one property grid.
Can you point me in the direction of tutorial type documentation for
property grid, the help doc explanations are difficult for me to grasp?

rgds,Steve

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******** *************@7 9g2000cws.googl egroups.com...
Normally this would be done via the type-converter of the property-type
(string in this case), which you obviously can't change in this
scenario. You could encapsulate the string into a simple class, and set
the converter for that, otherwise just set the converter for the
property:

using System;
using System.Componen tModel;
using System.Windows. Forms;
public class MyTest
{
private int test1;
public int Test1
{
get { return test1; }
set { test1 = value; }
}
private string test2;
[TypeConverter(t ypeof(StringLis tConverter))]
public string Test2
{
get { return test2; }
set { test2 = value; }
}
}
public class StringListConve rter : TypeConverter
{
public override bool
GetStandardValu esSupported(ITy peDescriptorCon text context)
{
return true; // display drop
}
public override bool
GetStandardValu esExclusive(ITy peDescriptorCon text context)
{
return true; // drop-down vs combo
}
public override StandardValuesC ollection
GetStandardValu es(ITypeDescrip torContext context)
{
// note you can also look at context etc to build list
return new StandardValuesC ollection(new string[] { "abc",
"def", "ghi" });
}
}
class Program
{
static void Main()
{
using (Form f = new Form())
using(PropertyG rid pg = new PropertyGrid())
{
pg.Dock = DockStyle.Fill;
pg.SelectedObje ct = new MyTest();
f.Controls.Add( pg);
Application.Run (f);
}
}
}

Dec 15 '06 #3
More example than tutorial; for what you want, the main thing is to
specify something like ExpandableObjec tConverter as a type descriptor.
However, much much more customisation is possible.

Example:

http://www.codeproject.com/cs/miscct...ectiondata.asp

Marc

Dec 15 '06 #4
descrpitor: I meant converter...

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******** **************@ t46g2000cwa.goo glegroups.com.. .
More example than tutorial; for what you want, the main thing is to
specify something like ExpandableObjec tConverter as a type
descriptor.
However, much much more customisation is possible.

Example:

http://www.codeproject.com/cs/miscct...ectiondata.asp

Marc

Dec 15 '06 #5

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

Similar topics

2
3967
by: Mevar81 | last post by:
Hi to everybody.I have a problem with the PropertyGrid control.I want to display not all the properties of a generic Control(Button,TextBox,ComboBox,ecc.).In general I don't want to display only one category(Appearance, Behavior,ecc.) but I want to chose directly which properties to show.I've read that I can use the SelectedObjects to put an...
3
4039
by: Frank Rizzo | last post by:
I added a PropertyGrid control to my form and set its SelectedObject property to one of my objects which exposes a lot of properties of type System.Drawing.Color. The System.Drawing.Color display fine, but they don't have a dropdown where I can select a new color, like in the VS.NET. How can I help the PropertyGrid display dropdowns for...
0
1034
by: Frank Rizzo | last post by:
Hello, I have the property grid control in my WinForm app. I have a property where I implemented a simple drop-down editor via the TypeConverter. I was wondering whether it is possible to add items to the dropdown after the application has initially populated it? For instance, consider the code below. In it, the ColorThemeManager...
0
2639
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem I am having is that when I have a value in the propertygird and edit that, I want the listbox to have the selectvalue equal to the value that is...
4
3295
by: Tugrul HELVACI | last post by:
Changing DisplayNames of my properties using PropertyGrid component, how ?? I'm using Delphi 2006 and I have a class defination like this: TPerson = class fPersonName : String; fPersonSurName : String; fPersonAge : Integer; published property PersonName : String read fPersonName write fPersonName;
4
18811
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 it seems to me that a PropertyGrid is a perfect modern replacement. I won't bore you with the details with all the controls on the dialog since I'm...
0
1137
by: Richy | last post by:
Hi, I am running VB Express 2005 and have been developing an application fine under Windows XP, but now I have switched to WIndows Vista I am getting strange behaviour with the PropertyGrid control. The problem not only happens on the IWindowsFormsEditorService that I have provided myself, but on the generic Color dropdown. When I click...
3
5183
by: Redivivus | last post by:
Hi Ho to use dropdown in propertygrid with values from database? Lets say i have table ITEMS and columns ID, NAME Now i want to select id, name from items and display those values in dropdown of my propertygrid
4
5441
by: Rohan | last post by:
I need to use the Collection editor of the propertyGrid, but i can't this to work, i looked around on the NET on collection and I am kinda lost. i have this so far, i don't know what i should do next Thank you Public class frmColor Dim xColors As New myColors
0
7808
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7732
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8063
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8243
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7822
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5302
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1062
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.