473,385 Members | 1,752 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,385 software developers and data experts.

How to write TypeConvert

I am writing a control and need to introduce custom nested property.
I need it to look exactly as XXXStyle properties for DataGrid.
I starting looking into TypeConverters and it seems that I need to override
ConvertTo and ConvertFrom methods. All the examples I saw show some custom
implementation of value - comer separated or semicolon separated values.
I need it to look the way it look in datagrid - xml.
Plus I have complex properties inside - like color and font.
How do I handle all this?

Thank you,
Shimon.
Nov 19 '05 #1
6 1451
Hi Shimon,

We have reviewed this issue and are currently researching on it. We will
update you ASAP. Thanks for your patience!

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 19 '05 #2
Hi Shimon,

Thanks for your posting. As for the defining Custom Type Convertor for
Nested Control property question, based on my experience, if your
Property's type class is normal class with some nested property (other
class type which are also basic types), they'll automatically appear in
VS.NET IDE's property window at design-time, and we can navigate them
through the +/- flag. In addition, for the
========
I need it to look the way it look in datagrid - xml.
========

I'm not quite sure on this, would you provide some further description on
this? Generally, the TypeConverter's two main method:
ConvertTo, ConvertFrom can help us cast discretionary object to the target
type (as long as the cast is valid).

Please feel free to post your further concerns here. Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: "Shimon Sim" <sh**********@community.nospam>
| Subject: How to write TypeConvert
| Date: Fri, 29 Jul 2005 12:26:37 -0400
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#f**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft .public.dotnet.framework.a
spnet.buildingcontrols
| NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:3947
microsoft.public.dotnet.framework.aspnet:115183
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I am writing a control and need to introduce custom nested property.
| I need it to look exactly as XXXStyle properties for DataGrid.
| I starting looking into TypeConverters and it seems that I need to
override
| ConvertTo and ConvertFrom methods. All the examples I saw show some
custom
| implementation of value - comer separated or semicolon separated values.
| I need it to look the way it look in datagrid - xml.
| Plus I have complex properties inside - like color and font.
| How do I handle all this?
|
| Thank you,
| Shimon.
|
|
|

Nov 19 '05 #3
Here's a sample I just happend to write up today (what *else* would I be
doing on a sunday). Also, sorry for the formatting:

[TypeConverter(typeof(LocationConverter))]
public struct Location
{
public Location(int x, int y)
{
_X = x;
_Y = y;
}
int _X;

[NotifyParentProperty(true)]
public int X
{
get { return _X; }
set { _X = value; }
}
int _Y;

[NotifyParentProperty(true)]
public int Y
{
get { return _Y; }
set { _Y = value; }
}
}

public class LocationConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context,
Type destinationType)
{
if (destinationType == typeof(string) ||
destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}

public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
Location l = (Location)value;
return string.Format("{0},{1}", l.X, l.Y);
}
if (destinationType == typeof(InstanceDescriptor))
{
Type t = typeof(Location);
ConstructorInfo ci = t.GetConstructor(new Type[] { typeof(int),
typeof(int) });
Location l = (Location)value;
InstanceDescriptor d = new InstanceDescriptor(ci, new object[]
{ l.X, l.Y });
return d;
}
return base.ConvertTo(context, culture, value, destinationType);
}

public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
Location l = new Location();
string[] parts = value.ToString().Split(',');
l.X = Int32.Parse(parts[0]);
l.Y = Int32.Parse(parts[1]);
return l;
}
return base.ConvertFrom(context, culture, value);
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi Shimon,

Thanks for your posting. As for the defining Custom Type Convertor for
Nested Control property question, based on my experience, if your
Property's type class is normal class with some nested property (other
class type which are also basic types), they'll automatically appear
in
VS.NET IDE's property window at design-time, and we can navigate them
through the +/- flag. In addition, for the
========
I need it to look the way it look in datagrid - xml.
========
I'm not quite sure on this, would you provide some further description
on
this? Generally, the TypeConverter's two main method:
ConvertTo, ConvertFrom can help us cast discretionary object to the
target
type (as long as the cast is valid).
Please feel free to post your further concerns here. Thanks,

Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Shimon Sim" <sh**********@community.nospam>
| Subject: How to write TypeConvert
| Date: Fri, 29 Jul 2005 12:26:37 -0400
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#f**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft .public.dotnet.frame
work.a
spnet.buildingcontrols
| NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
| Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:3947
microsoft.public.dotnet.framework.aspnet:115183
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I am writing a control and need to introduce custom nested property.
| I need it to look exactly as XXXStyle properties for DataGrid.
| I starting looking into TypeConverters and it seems that I need to
override
| ConvertTo and ConvertFrom methods. All the examples I saw show some
custom
| implementation of value - comer separated or semicolon separated
values.
| I need it to look the way it look in datagrid - xml.
| Plus I have complex properties inside - like color and font.
| How do I handle all this?
|
| Thank you,
| Shimon.
|
|
|


Nov 19 '05 #4
Thank a lot.
I saw similar code in the MSDN example - can't understand one thing - there
this 'value' comes from? How is it stored in the page?

Thanks
Shimon.

"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:10***********************@msnews.microsoft.co m...
Here's a sample I just happend to write up today (what *else* would I be
doing on a sunday). Also, sorry for the formatting:

[TypeConverter(typeof(LocationConverter))]
public struct Location
{
public Location(int x, int y)
{
_X = x;
_Y = y;
}
int _X;

[NotifyParentProperty(true)]
public int X
{
get { return _X; }
set { _X = value; }
}
int _Y;

[NotifyParentProperty(true)]
public int Y
{
get { return _Y; }
set { _Y = value; }
}
}

public class LocationConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context,
Type destinationType)
{
if (destinationType == typeof(string) ||
destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}

public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType)
{
if (destinationType == typeof(string))
{
Location l = (Location)value;
return string.Format("{0},{1}", l.X, l.Y);
}
if (destinationType == typeof(InstanceDescriptor))
{
Type t = typeof(Location);
ConstructorInfo ci = t.GetConstructor(new Type[] {
typeof(int), typeof(int) });
Location l = (Location)value;
InstanceDescriptor d = new InstanceDescriptor(ci, new
object[] { l.X, l.Y });
return d;
}
return base.ConvertTo(context, culture, value,
destinationType);
}

public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
Location l = new Location();
string[] parts = value.ToString().Split(',');
l.X = Int32.Parse(parts[0]);
l.Y = Int32.Parse(parts[1]);
return l;
}
return base.ConvertFrom(context, culture, value);
}
}

-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi Shimon,

Thanks for your posting. As for the defining Custom Type Convertor for
Nested Control property question, based on my experience, if your
Property's type class is normal class with some nested property (other
class type which are also basic types), they'll automatically appear
in
VS.NET IDE's property window at design-time, and we can navigate them
through the +/- flag. In addition, for the
========
I need it to look the way it look in datagrid - xml.
========
I'm not quite sure on this, would you provide some further description
on
this? Generally, the TypeConverter's two main method:
ConvertTo, ConvertFrom can help us cast discretionary object to the
target
type (as long as the cast is valid).
Please feel free to post your further concerns here. Thanks,

Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: "Shimon Sim" <sh**********@community.nospam>
| Subject: How to write TypeConvert
| Date: Fri, 29 Jul 2005 12:26:37 -0400
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#f**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft .public.dotnet.frame
work.a
spnet.buildingcontrols
| NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
| Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:3947
microsoft.public.dotnet.framework.aspnet:115183
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I am writing a control and need to introduce custom nested property.
| I need it to look exactly as XXXStyle properties for DataGrid.
| I starting looking into TypeConverters and it seems that I need to
override
| ConvertTo and ConvertFrom methods. All the examples I saw show some
custom
| implementation of value - comer separated or semicolon separated
values.
| I need it to look the way it look in datagrid - xml.
| Plus I have complex properties inside - like color and font.
| How do I handle all this?
|
| Thank you,
| Shimon.
|
|
|


Nov 19 '05 #5
TypeConverters are used when the developer is chaning the data in the property
page for a property of your contorl. The property page is a text entry form
-- there needs to be some way to take the text and convert it to the strongly
typed property on your control. So the value is passed in by VS.NET from
what the user types in the property page.

-Brock
DevelopMentor
http://staff.develop.com/ballen
Thank a lot.
I saw similar code in the MSDN example - can't understand one thing -
there
this 'value' comes from? How is it stored in the page?
Thanks
Shimon.
"Brock Allen" <ba****@NOSPAMdevelop.com> wrote in message
news:10***********************@msnews.microsoft.co m...
Here's a sample I just happend to write up today (what *else* would I
be doing on a sunday). Also, sorry for the formatting:

[TypeConverter(typeof(LocationConverter))]
public struct Location
{
public Location(int x, int y)
{
_X = x;
_Y = y;
}
int _X;
[NotifyParentProperty(true)]
public int X
{
get { return _X; }
set { _X = value; }
}
int _Y;
[NotifyParentProperty(true)]
public int Y
{
get { return _Y; }
set { _Y = value; }
}
}
public class LocationConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context,
Type destinationType)
{
if (destinationType == typeof(string) ||
destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override bool CanConvertFrom(ITypeDescriptorContext context,
Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type
destinationType)
{
if (destinationType == typeof(string))
{
Location l = (Location)value;
return string.Format("{0},{1}", l.X, l.Y);
}
if (destinationType == typeof(InstanceDescriptor))
{
Type t = typeof(Location);
ConstructorInfo ci = t.GetConstructor(new Type[] {
typeof(int), typeof(int) });
Location l = (Location)value;
InstanceDescriptor d = new InstanceDescriptor(ci, new
object[] { l.X, l.Y });
return d;
}
return base.ConvertTo(context, culture, value,
destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value)
{
if (value is string)
{
Location l = new Location();
string[] parts = value.ToString().Split(',');
l.X = Int32.Parse(parts[0]);
l.Y = Int32.Parse(parts[1]);
return l;
}
return base.ConvertFrom(context, culture, value);
}
}
-Brock
DevelopMentor
http://staff.develop.com/ballen
Hi Shimon,

Thanks for your posting. As for the defining Custom Type Convertor
for
Nested Control property question, based on my experience, if your
Property's type class is normal class with some nested property
(other
class type which are also basic types), they'll automatically appear
in
VS.NET IDE's property window at design-time, and we can navigate
them
through the +/- flag. In addition, for the
========
I need it to look the way it look in datagrid - xml.
========
I'm not quite sure on this, would you provide some further
description
on
this? Generally, the TypeConverter's two main method:
ConvertTo, ConvertFrom can help us cast discretionary object to the
target
type (as long as the cast is valid).
Please feel free to post your further concerns here. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers
no
rights.)
--------------------
| From: "Shimon Sim" <sh**********@community.nospam>
| Subject: How to write TypeConvert
| Date: Fri, 29 Jul 2005 12:26:37 -0400
| Lines: 13
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <#f**************@TK2MSFTNGP10.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet,microsoft .public.dotnet.fra
me
work.a
spnet.buildingcontrols
| NNTP-Posting-Host: ool-44c05922.dyn.optonline.net 68.192.89.34
| Path:
TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP10.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet.buildingc ontrols:3947
microsoft.public.dotnet.framework.aspnet:115183
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| I am writing a control and need to introduce custom nested
property.
| I need it to look exactly as XXXStyle properties for DataGrid.
| I starting looking into TypeConverters and it seems that I need to
override
| ConvertTo and ConvertFrom methods. All the examples I saw show
some
custom
| implementation of value - comer separated or semicolon separated
values.
| I need it to look the way it look in datagrid - xml.
| Plus I have complex properties inside - like color and font.
| How do I handle all this?
|
| Thank you,
| Shimon.
|
|
|


Nov 19 '05 #6
Hi,

it doesn't need a type converter (it is meant for converting complex object
to string so that it can also be parsed back from markup to represent a
property).

Instead you make the style property read-only, and apply

[NotifyParentProperty(true),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)]

attributes to the property.

The style property could look something like this

[NotifyParentProperty(true),
DesignerSerializationVisibility(DesignerSerializat ionVisibility.Content),
PersistenceMode(PersistenceMode.InnerProperty)]
public virtual TableItemStyle ItemStyle
{
get
{
if (this.itemStyle == null)
{
this.itemStyle = new TableItemStyle();
if (base.IsTrackingViewState)
{
this.itemStyle.TrackViewState();
}
}
return this.itemStyle;
}
}
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke


"Shimon Sim" <sh**********@community.nospam> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
I am writing a control and need to introduce custom nested property.
I need it to look exactly as XXXStyle properties for DataGrid.
I starting looking into TypeConverters and it seems that I need to
override ConvertTo and ConvertFrom methods. All the examples I saw show
some custom implementation of value - comer separated or semicolon
separated values.
I need it to look the way it look in datagrid - xml.
Plus I have complex properties inside - like color and font.
How do I handle all this?

Thank you,
Shimon.

Nov 19 '05 #7

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

Similar topics

10
by: Greg Hurlman | last post by:
I've got what I'm sure is a very simple problem. In an ASP page, I am trying to write out 4 fields from a recordset in succession: Response.Write rs("LastName") Response.Write rs("Suffix")...
1
by: techy techno | last post by:
Hii Just wanted to know how can I decorate my texboxes and Listmenu which is called from a JS file using the following code below: document.write("<SELECT NAME='cur2' ONCHANGE='cconv1();'>");...
2
by: Brett Baisley | last post by:
Hello I have a block of html code that I want to run by calling a javascript function to print it. Its basically a table with menu items in it that is the same for many pages, and instead of...
0
by: hari krishna | last post by:
hi all, My requirement is to generate xl reports throu Asp.Net without installing xl on web server computer. i am using Response object and wrtifile method as below. i dont know whether it is...
8
by: Ben | last post by:
Hi all, Just wondering how to write (using document.write) to a table cell. I have table with 3 rows and 3 colums. I want to write from within the Javascript to say third column of a first row....
4
by: Prowler | last post by:
In the application we are currently building, we need to write positioning code on-the-fly, based upon the screen offset of the element in the AS/400 application which drives the Web app. The 400,...
11
by: Vmusic | last post by:
Hi, I am trying to write out an array of string variables to Notepad. I can't get SendKeys to accept the string variable only literal quoted strings. I DO NOT want the hassle of writing to a...
4
by: cbtechlists | last post by:
I have an ASP app that we've moved from a Windows 2000 to a Windows 2003 server (sql server 2000 to sql server 2005). The job runs fine on the old servers. Part of the app takes a recordset and...
0
by: kuguy | last post by:
Hi all, I'm new to the forums, so I hope this isn't in the wrong place... I have that "Software caused connection abort: socket write error" exception error that i've never meet before. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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,...

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.