I have created ExpandableObjec tConverter in C#. for use in
System.Windows. Forms.PropertyG rid.
The property grid shows the DiffItem is a object that holds member
TheItem.
without expanding TheItem
It works if u click, select from drop down box. until you DoubleClick
it shows error:
"Invalid property Value". with "Object type cannot be converted to
target type."
Here is a code:
public class ItemConverter:E xpandableObject Converter
{
public override bool CanConvertTo(IT ypeDescriptorCo ntext context, Type
destinationType )
{
if(destinationT ype == typeof(TheItem) ) return true;
return base.CanConvert To (context, destinationType );
}
public override object ConvertTo(IType DescriptorConte xt context,
CultureInfo culture, object value, Type destinationType )
{
if(destinationT ype == typeof(System.S tring) && value is TheItem)
{
return ((TheItem)value ).Rating;
}
object ret = base.ConvertTo (context, culture, value, destinationType );
//Line 1
return ret;
}
public override bool GetStandardValu esSupported( ITypeDescriptor Context
context)
{
return true;
}
public override bool GetStandardValu esExclusive( ITypeDescriptor Context
context)
{
return true;
}
public override StandardValuesC ollection
GetStandardValu es(ITypeDescrip torContext context)
{
if( context.Instanc e is DiffItem )
{
//Line 2
return new StandardValuesC ollection(new string[]
{"N/R","A","B","C", "D","E"});
}
return base.GetStandar dValues (context);
}
public override bool CanConvertFrom( ITypeDescriptor Context context,
Type sourceType)
{
if(sourceType == typeof(string))
return true;
return base.CanConvert From (context, sourceType);
}
public override object ConvertFrom(ITy peDescriptorCon text context,
CultureInfo culture, object value)
{
if( value is string )
{
if(context.Inst ance is TheItem)
{
TheItem item = new TheItem((string ) value,DateTime. Now);
return item;
}
if( context.Instanc e is DiffItem )
{
DiffItem diff = (DiffItem )context.Instan ce;
TheItem rating=diff.Rat ing;
TheItem item = new TheItem ((string) value,rating.th eDate);
return item;
}
}
return base.ConvertFro m (context, culture, value);
}
}
//the Item class
[TypeConverterAt tribute(typeof( ItemConverter))]
public class TheItem
{
string rating="N/A";
DateTime theDate=DateTim e.Min;
#region Constructors
public TheItem()
{}
public TheItem(string value, DateTime thedate )
{
this.rating=val ue;
this.theDate=th edate ;
}
#endregion
#region Properties
[DescriptionAttr ibute("The Rating itself."),
DefaultValueAtt ribute("N/A"),
RefreshProperti esAttribute(Ref reshProperties. All),
ReadOnlyAttribu te(false)]
public string Rating
{
get{return rating;}
set{rating=valu e;}
}
[DescriptionAttr ibute("Rating Date."),
ReadOnlyAttribu te(false)]
public DateTime RatingDate
{
get{return theDate;}
set{theDate=val ue;}
}
#endregion
}
}
where DiffItem is a object that holds member TheItem:
[CategoryAttribu te("Ratings"),
ReadOnlyAttribu te(false)]
public TheItem TheRating
{
get { return rating; }
set { rating=value; }
}
I have debug the code...
it goes to //line 2 (see the code)
and gets the values.
then it goes to //line 1
and loop trough all possible values.
The again goes to //line 2 and then shows the error.
Any help how to fix this welcome.
Thank you \/|@d. 0 3044 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Brian Young |
last post by:
Hi all.
I'm using the Property Grid control in a control to manage a windows service
we have developed here. The windows service runs a set of other jobs that
need to be managed. The control is used to view the state of the running
jobs and schedule new jobs. The control also runs in the context of
Internet Explorer (we do this so the administrators of the jobs can always
receive the latest control). The property grid is used to...
|
by: Steve Barnett |
last post by:
I have a field in a user control which is a structure. The structure has
three fields, an integer a string and a Boolean. When I put my user control
on a form, the property that references the structure is greyed out, so I
can't set any of the fields of the structure.
Is there something I should be doing to make the fields of my structure
available in the properties editor for a form?
Thanks
Steve
|
by: John Kraft |
last post by:
Hi all,
I'm trying to use a property grid, and what I'm trying to do seems to
really elude me. I've been using the property grid for a short period
of time, and this is the first thing I haven't been able to do.
I have some products... like t-shirts... and these products have
particular property / value pairs. I'd like the property grid to look
like this:
|
by: Lespaul36 |
last post by:
I have a control that I have made that uses a custom class for storage of
some of the information. I want it to display in the VS.Net 2003 property
grid in the IDE like the Font property does, so a use can expand it and set
the properties. How do I do this? Thanks in advance.
|
by: Ron M. Newman |
last post by:
Hi,
I have a problem with dynamically putting dynamic properties on the property
grid. My app has no idea what it'll be showing at compile time.
How do I dynamically add properties to the property grid?
Thanks,
Ron
| |
by: margelos |
last post by:
I have created the following usercontrol
public class RegisterUser : TemplatedWebControl {
private VisFields _vfields = new VisFields();
public VisFields VisibleFields {
get { return _vfields; }
set { _vfields = value; }
}
|
by: --== Alain ==-- |
last post by:
Hi,
I have a huge problem...
My property does not appear in the "propertyGrid" of "test Container",
when i test my custom control.
Here is the custom control code :
namespace ARListView.Design
{
|
by: --== Alain ==-- |
last post by:
Hi,
I finally found how to update the render of my custom control when one
of its property value changed.
However, i would like to know if there is not another way, because i'm
afraid about memory usage or leak.
The following code is only a change color property update, but it is
easy to adapt it to other properties.
|
by: Hans Koller |
last post by:
Hello group,
I design a class to bind it to a property grid for easy modification
of some settings. My problem is now that I want to raise an event when
a settings has been changed.
Thats not a problem with some "normal" properties (see property
DisplayGrid). But when I use a subclass and TypeConverter the setter
of the property is not called.
Set(ByVal value As LineSetting)
m_Limit1 = value
|
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: 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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |