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? 4 35984
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);
}
}
}
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);
}
}
}
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 array of object with some
properties in common with the SelectedObject,and only
properties in...
|
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
System.Drawing.Color properties?
Thanks
|
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 exposes in the
dropdown the list of files with the .ColorTheme extention. At some
point, the another...
|
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 being edited. Just to make it
clearer:
PropgridVal = Germany
Datasource=
|
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;
| |
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
only concerned with one issue. The legacy dialog contains a drop down
list control that is...
|
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 the dropdown arrow next to a property in the Grid (be it
Color or one of my own), one of three...
|
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
|
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
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |