What is an Ignore list?
PropertyGrid + FileNameEditor + TypeConverter not working.
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What can I do?
• What to Read?
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Зарегистрируйся!

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:
  Moderators:

PropertyGrid + FileNameEditor + TypeConverter not working.

Jamie Seward 19 September 2008 09:30:04
 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:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или УК РФ.


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

see also:
Java Heap Memory Error
how to pass multiple records (ref…
[Support] Request for info (fwd)
пройди тесты:
Do you know women?
see also:
server error message
Seven most perspective Social web…

  Copyright © 2001—2008 QAIX
Idea: Miсhael Monashev
Помощь и задать вопросы можно в сообществе support.qaix.com.
Сообщения об ошибках оставляем в сообществе bugs.qaix.com.
Предложения и комментарии пишем в сообществе suggest.qaix.com.
Информация для родителей.
Write us at:
If you would like to report an abuse of our service, such as a spam message, please .