473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

issue when linking a TypeConverter to property

Hi,

I 'm facing an interesting issue regarding a property and its TypeConverter.

When i do not attach a TypeConverter to this property, all custom
properties of my custom control are displayed in Test Container.

Since i attached this TypeConverter to my property, ALL custom
properties (properties implemented by myself) are not displayed in Test
Container.

therefore, i guess something is wrong with the TypeConverter or the way
how i attached it to my property.

here it is how i attached it :
[TypeConverter(typeof(CGridLineConverter))]
public CGridLine GridLines
{
...
}

and here is the typeconverter class i've developed ;

public class CGridLineConverter : ExpandableObjectConverter
{
/// <summary>
/// Check if it the parameter (context) is a string and can convert
it to class type (destinationType)
/// </summary>
/// <param name="context">string that holds the class type
information</param>
/// <param name="destinationType">class type to which the context
must be converted</param>
/// <returns>true if it's possible, or false in case of impossible
conversion</returns>
public override bool CanConvertTo(ITypeDescriptorContext
context,Type destinationType)
{
if (destinationType == typeof(string))
return true;
else
return base.CanConvertTo(context, destinationType);
}

/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="culture"></param>
/// <param name="value"></param>
/// <param name="destinationType"></param>
/// <returns></returns>
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
return ConvertToString(value);
else
return base.ConvertTo(context, culture, value, destinationType);
}

/// <summary>
/// ConverToString whole subproperties
/// </summary>
/// <param name="value">value holds by CGridLine property</param>
/// <returns>Formatted string that holds the CGridLine property
converted into text</returns>
public string ConvertToString(object value)
{
CGridLine GridLine = (CGridLine)value;
ColorConverter ColorConverter = new ColorConverter();
return String.Format("{0}, {1}, {2}",
GridLine.Lines,
GridLine.Style,
ColorConverter.ConvertToString(GridLine.Color));
}

public override bool CanConvertFrom(ITypeDescriptorContext
context,Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
return ConvertFromString(value);
else
return base.ConvertFrom(context, culture, value);
}

public CGridLine ConvertFromString(object value)
{
string[] values = ((string)value).Split(',');
if (values.Length != 3)
throw new ArgumentException("Could not convert the value !");
try
{
CGridLine GridLine = new CGridLine();
ColorConverter ColorConverter = new ColorConverter();
StringConverter StringConverter = new StringConverter();

GridLine.Lines =
(GridLines)StringConverter.ConvertFromString(value s[0]);
GridLine.Style =
(GridLineStyle)StringConverter.ConvertFromString(v alues[1]);
GridLine.Color =
(Color)ColorConverter.ConvertFromString(values[2]);

// Convert the name of the enumerated value into the corresponding
// enumerated value (which is actually an integer constant).

return GridLine;
}
catch (Exception err)
{
String ErrorMsg = "Could not convert the value \n\n Error
Message : " + err.Message;
//Debug.WriteLine("test");
throw new ArgumentException(ErrorMsg);
}
}
}
please, could you help me ?
thx.

Al.

Feb 10 '07 #1
1 2142
Hi,

I would like to add an another point.
I have the same problem if i develop my own property editor and attach
it to some class property.

All other properties (that i implemented) from this class, are not
displayed in the Test Container.

Is there a special step to do to make those things : TypeConverter and
TypeEditor ?

thanks.

Al.

--== Alain ==-- wrote:
Hi,

I 'm facing an interesting issue regarding a property and its
TypeConverter.

When i do not attach a TypeConverter to this property, all custom
properties of my custom control are displayed in Test Container.

Since i attached this TypeConverter to my property, ALL custom
properties (properties implemented by myself) are not displayed in Test
Container.

therefore, i guess something is wrong with the TypeConverter or the way
how i attached it to my property.

here it is how i attached it :
[TypeConverter(typeof(CGridLineConverter))]
public CGridLine GridLines
{
...
}

and here is the typeconverter class i've developed ;

public class CGridLineConverter : ExpandableObjectConverter
{
/// <summary>
/// Check if it the parameter (context) is a string and can convert
it to class type (destinationType)
/// </summary>
/// <param name="context">string that holds the class type
information</param>
/// <param name="destinationType">class type to which the context
must be converted</param>
/// <returns>true if it's possible, or false in case of impossible
conversion</returns>
public override bool CanConvertTo(ITypeDescriptorContext
context,Type destinationType)
{
if (destinationType == typeof(string))
return true;
else
return base.CanConvertTo(context, destinationType);
}

/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="culture"></param>
/// <param name="value"></param>
/// <param name="destinationType"></param>
/// <returns></returns>
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
return ConvertToString(value);
else
return base.ConvertTo(context, culture, value, destinationType);
}

/// <summary>
/// ConverToString whole subproperties
/// </summary>
/// <param name="value">value holds by CGridLine property</param>
/// <returns>Formatted string that holds the CGridLine property
converted into text</returns>
public string ConvertToString(object value)
{
CGridLine GridLine = (CGridLine)value;
ColorConverter ColorConverter = new ColorConverter();
return String.Format("{0}, {1}, {2}",
GridLine.Lines,
GridLine.Style,
ColorConverter.ConvertToString(GridLine.Color));
}

public override bool CanConvertFrom(ITypeDescriptorContext
context,Type sourceType)
{
if (sourceType == typeof(string))
return true;
else
return base.CanConvertFrom(context, sourceType);
}

public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
return ConvertFromString(value);
else
return base.ConvertFrom(context, culture, value);
}

public CGridLine ConvertFromString(object value)
{
string[] values = ((string)value).Split(',');
if (values.Length != 3)
throw new ArgumentException("Could not convert the value !");
try
{
CGridLine GridLine = new CGridLine();
ColorConverter ColorConverter = new ColorConverter();
StringConverter StringConverter = new StringConverter();

GridLine.Lines =
(GridLines)StringConverter.ConvertFromString(value s[0]);
GridLine.Style =
(GridLineStyle)StringConverter.ConvertFromString(v alues[1]);
GridLine.Color =
(Color)ColorConverter.ConvertFromString(values[2]);

// Convert the name of the enumerated value into the corresponding
// enumerated value (which is actually an integer constant).

return GridLine;
}
catch (Exception err)
{
String ErrorMsg = "Could not convert the value \n\n Error
Message : " + err.Message;
//Debug.WriteLine("test");
throw new ArgumentException(ErrorMsg);
}
}
}
please, could you help me ?
thx.

Al.
Feb 11 '07 #2

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

Similar topics

2
by: João Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New...
0
by: João Santa Bárbara | last post by:
Hi all i have a class that i have made and i made an Typeconverter as well, and my problem is the code genereated in my form is Dim ClassTest1 As TestApplication.ClassTest = New...
6
by: Kerry Sanders | last post by:
I am working on a project for work where I need a specialized type converter to convert the value of a string which is edited in a grid back to the underlying object type from the cell. The value...
2
by: kw | last post by:
I'm getting different behavior from what I would expect and was hoping someone could clue me in. At run time I need to examine a property of an object for a custom TypeConverter, then use that...
5
by: ljlevend | last post by:
Is there a TypeConverter that converts Doubles to percent values in a PropertyGrid? The Windows.Forms.Form.Opacity property seems to use the TypeConverter that I want. Thank you, Lance
0
by: Eric Hoch | last post by:
Hello, I'm writing a TypeConverter for a class which inherits arraylist, but deserializing it always results in an arraylist, which causes an InvalidCastException. If anyone can point out what...
1
by: Matthias Heise | last post by:
Hello everybody, I have a problem towards the following topic. There is a class like MyColor and a class like MyRectangle that has a property called FillColor which is of type MyColor. Now it...
0
by: movieknight | last post by:
Hi, I have a class which I am feeding to the propertygrid, and I am exposing a Mesh object from my class for the propertygrid to display. I want the propertygrid to show the values (when you...
4
by: swartzbill2000 | last post by:
Hello, I have a TypeConverter for converting between this Enum and Strings. Public Enum DeviceNameEnum dnNone dn2500 dnMirror End Enum 'DeviceNameEnum
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
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...
0
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,...
0
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...
0
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...
0
tracyyun
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...
0
agi2029
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,...

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.