Can I subscribe to information on new tests?
PropertyGrid + FileNameEditor + TypeConverter not working.
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Ñîîáùåñòâà
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > .Net Development > PropertyGrid + FileNameEditor + TypeConverter not working. 19 September 2008 09:30:04

  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Ìîäåðàòîð:

PropertyGrid + FileNameEditor + TypeConverter not working.

Jamie Seward 12 May 2004 15:04:22
 I am having difficulty getting a FileNameEditor working with a Property that get/sets a custom Type (let's call it TextureNameType).



First here is what does work:

1) If I add the FileNameEditor attribute to a Property that get/sets a System::String everything works fine. I can open up the OpenFileDialog and it will change the Property as desired.

2) If I change the Property from a System::String to a TextureNameType (that has a fully operational TextureNameTypeConv­erter attribute) everything works fine. I can edit the field in the Property Grid and it will convert to and from a System::String properly.



The problem is when I try to give both attributes (FileNameEditor / TextureNameTypeConv­erter) to TextureNameType at the same time. The OpenFileDialog will open but selecting a file will bring up: "Invalid property value: Object type cannot be converted to target type."

I have set breakpoints in the TextureNameTypeConv­erter functions and it doesn't hit any of them. So it seems the PropertyGrid doesn't even check my TextureNameTypeConv­erter to see if it can convert the value returned by the FileNameEditor.

Does anyone know what is causing this? Thanks for any help!


Note: all of the classes are in a Managed C++ Class Library. The PropertyGrid is in a C# project.


Jamie Seward


===================­================
This list is hosted by DevelopMentor® http://www.develop.­com
Some .NET courses you may be interested in:

Guerrilla ASP.NET, May 17, 2004, in Los Angeles
http://www.develop.­com/courses/gaspdotn­etls

Guerrilla.NET, June 28, 2004, in Los Angeles
http://www.develop.­com/courses/gdotnetl­s

Guerrilla.NET, July 5, 2004, in London. UK
http://www.develop.­com/courses/gdotnetl­s

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
Chris Day 13 May 2004 03:50:17 permanent link ]
 Having used the propertygrid a fair bit I can only tell you what I know
from experience.

When you append a class with a TypeConverter attribute the PropertyGrid
uses the class specified to convert the value of the property, usually
to a string. If there is set method on the property and no Editor
attribute is specied it also uses the TypeConverter class to convert the
input, also usually a string (it would be hard for it to be anything
else).

If an Editor attribute is specified the PropertyGrid delegates all
responsibility for altering the value of the property to the Editor
using the return of the editor to set the property, not bothering to
look at the TypeConverter attribute because it assumes that the Editor
knows whats it's doing and returning an object of the right type. This
is obviously what is causing the exception.

What I suggest you do is to derive from FileNameEditor thusly

public class TextureNameTypeEdit­or : FileNameEditor
{
public override object EditValue(ITypeDesc­riptorContext context,
IServiceProvider provider, object value)
{
object obj = base.EditValue(cont­ext, provider, value);
TextureNameType tnt = TextureNameType.Con­vert(obj); // or whatever
you need to do
return tnt;
}
}

Then add an [Editor(typeof(TextureNameTypeEditor))] to your property.

Chris
-----Original Message-----> From: Jamie Seward [mailto:jseward@IRONCLADGAMES.COM] > Sent: Wednesday, 12 May 2004 10:04 PM> To: DOTNET-CLR@DISCUSS.­DEVELOP.COM> Subject: [DOTNET-CLR] PropertyGrid + FileNameEditor + > TypeConverter not working.>
I am having difficulty getting a FileNameEditor working with > a Property that get/sets a custom Type (let's call it > TextureNameType).>
First here is what does work:>
1) If I add the FileNameEditor attribute to a Property that > get/sets a System::String everything works fine. I can open > up the OpenFileDialog and it will change the Property as desired.>
2) If I change the Property from a System::String to a > TextureNameType (that has a fully operational > TextureNameTypeConv­erter attribute) everything works fine. I > can edit the field in the Property Grid and it will convert > to and from a System::String properly.>
The problem is when I try to give both attributes > (FileNameEditor / TextureNameTypeConv­erter) to > TextureNameType at the same time. The OpenFileDialog will > open but selecting a file will bring up: "Invalid property > value: Object type cannot be converted to target type.">
I have set breakpoints in the TextureNameTypeConv­erter > functions and it doesn't hit any of them. So it seems the > PropertyGrid doesn't even check my TextureNameTypeConv­erter > to see if it can convert the value returned by the FileNameEditor.>
Does anyone know what is causing this? Thanks for any help!>
Note: all of the classes are in a Managed C++ Class Library. > The PropertyGrid is in a C# project.>
Jamie Seward>
===================­================> This list is hosted by DevelopMentor(r) http://www.develop.­com > Some .NET courses you may be interested in:>
Guerrilla ASP.NET, May 17, 2004, in Los Angeles > http://www.develop.­com/courses/gaspdotn­etls>
View archives and manage your subscription(s) at > http://discuss.deve­lop.com>

===================­================
This list is hosted by DevelopMentor http://www.develop.­com
Some .NET courses you may be interested in:

Guerrilla ASP.NET, May 17, 2004, in Los Angeles
http://www.develop.­com/courses/gaspdotn­etls

Guerrilla.NET, June 28, 2004, in Los Angeles
http://www.develop.­com/courses/gdotnetl­s

Guerrilla.NET, July 5, 2004, in London. UK
http://www.develop.­com/courses/gdotnetl­s

View archives and manage your subscription(s) at http://discuss.deve­lop.com

Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
respect your talk pals, avoid using obscene language, typing entire messages in CAPS, posting buy/sell ads or violating netiquette or the RF Criminal Code..


QAIX > .Net Development > PropertyGrid + FileNameEditor + TypeConverter not working. 19 September 2008 09:30:04

see also:
not sure if this is a beginners issue…
Favorite Perl CGI Framework for Web…
Re: Extracting links. - without modules
pass tests:
see also:
World’s Most Unusual Christmas Trees

  Copyright © 2001—2009 QAIX
Idea: Miñhael Monashev
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .