473,738 Members | 1,949 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(t ypeof(CGridLine Converter))]
public CGridLine GridLines
{
...
}

and here is the typeconverter class i've developed ;

public class CGridLineConver ter : ExpandableObjec tConverter
{
/// <summary>
/// Check if it the parameter (context) is a string and can convert
it to class type (destinationTyp e)
/// </summary>
/// <param name="context"> string that holds the class type
information</param>
/// <param name="destinati onType">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(IT ypeDescriptorCo ntext
context,Type destinationType )
{
if (destinationTyp e == typeof(string))
return true;
else
return base.CanConvert To(context, destinationType );
}

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

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

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

public override object ConvertFrom(ITy peDescriptorCon text context,
CultureInfo culture, object value)
{
if (value is string)
return ConvertFromStri ng(value);
else
return base.ConvertFro m(context, culture, value);
}

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

GridLine.Lines =
(GridLines)Stri ngConverter.Con vertFromString( values[0]);
GridLine.Style =
(GridLineStyle) StringConverter .ConvertFromStr ing(values[1]);
GridLine.Color =
(Color)ColorCon verter.ConvertF romString(value s[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 ArgumentExcepti on(ErrorMsg);
}
}
}
please, could you help me ?
thx.

Al.

Feb 10 '07 #1
1 2157
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(t ypeof(CGridLine Converter))]
public CGridLine GridLines
{
...
}

and here is the typeconverter class i've developed ;

public class CGridLineConver ter : ExpandableObjec tConverter
{
/// <summary>
/// Check if it the parameter (context) is a string and can convert
it to class type (destinationTyp e)
/// </summary>
/// <param name="context"> string that holds the class type
information</param>
/// <param name="destinati onType">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(IT ypeDescriptorCo ntext
context,Type destinationType )
{
if (destinationTyp e == typeof(string))
return true;
else
return base.CanConvert To(context, destinationType );
}

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

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

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

public override object ConvertFrom(ITy peDescriptorCon text context,
CultureInfo culture, object value)
{
if (value is string)
return ConvertFromStri ng(value);
else
return base.ConvertFro m(context, culture, value);
}

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

GridLine.Lines =
(GridLines)Stri ngConverter.Con vertFromString( values[0]);
GridLine.Style =
(GridLineStyle) StringConverter .ConvertFromStr ing(values[1]);
GridLine.Color =
(Color)ColorCon verter.ConvertF romString(value s[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 ArgumentExcepti on(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
2195
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 TestApplication.ClassTest Me.MyClassTest = ClassTest1 Wich is quite good, but my problem is in my property browser i cannot change any of my properties
0
1238
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 TestApplication.ClassTest Me.MyClassTest = ClassTest1 Wich is quite good, but my problem is in my property browser i cannot change any of my properties
6
5665
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 in the cell is displayed as a string from the ToString() method in the class. Anyway, I am trying to implement my converter, but I am having a little trouble understanding it fully and how exactly to implement some of the methods, especially...
2
3419
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 converter on a value. Here's the deal: object attrs=(object)PropertyInfo.GetCustomAttributes(typeof(TypeConverterAttribu te),false);
5
2187
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
1212
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 I'm doing wrong here, I'd really appreciate it. The class: <TypeConverter(GetType(CXMLObjectListConverter))> _
1
1483
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 should be able to say MyRectangle rect1 = new MyRectangle(); rect1.FillColor = "Red";
0
1534
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 expand the property) and allow those values to be edited. My code is below. The grid is showing the values but they are read-only, although the other properties for the rest of my class are editable. Public Class MeshConverter
4
1701
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
8968
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9473
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9334
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9208
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 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...
0
8208
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, 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...
1
6750
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6053
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();...
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.