PC Review


Reply
Thread Tools Rate Thread

how to change the item type display name in pop up collectioneditor

 
 
colin
Guest
Posts: n/a
 
      25th Jun 2008
Hi,
I have my property editor wich uses the pop up
collection editor for arrays etc,
but i have had to use a generic wrapper for the
elements in some types of collections.

although the editing actually works well,
and I can set the name ok in the primary property editor,
this makes a mess of the type name displayed in the pop up colection editor,
is there any way to change this ?

eg

class UWrapper<T>:List<T>
{
T Item{get{}}
}
UWrapper<Vector> collection;

the collection gets displayed as UWrapper'1
in the title and also the same in the edit value box.

but I would like this to be displayed as Vector or whatever
the generic type is im using.

Ive tried all sorts of attributes and classes but cant seem
to figure this onr out. the pop up colection editor
seems to work diferently than the property editor.


Many thanks
Colin =^.^=







 
Reply With Quote
 
 
 
 
colin
Guest
Posts: n/a
 
      25th Jun 2008
oops that shoud of been

class UCollection<T>:List<T>
{
T Item{get{}}
}

public class UWrapper<T>
{
}

UCollection<UWrapper<Vector>> collection;



"colin" <(E-Mail Removed)> wrote in message
news:Nmy8k.63066$(E-Mail Removed)2...
> Hi,
> I have my property editor wich uses the pop up
> collection editor for arrays etc,
> but i have had to use a generic wrapper for the
> elements in some types of collections.
>
> although the editing actually works well,
> and I can set the name ok in the primary property editor,
> this makes a mess of the type name displayed in the pop up colection
> editor,
> is there any way to change this ?
>
> eg
>
> class UWrapper<T>:List<T>
> {
> T Item{get{}}
> }
> UWrapper<Vector> collection;
>
> the collection gets displayed as UWrapper'1
> in the title and also the same in the edit value box.
>
> but I would like this to be displayed as Vector or whatever
> the generic type is im using.
>
> Ive tried all sorts of attributes and classes but cant seem
> to figure this onr out. the pop up colection editor
> seems to work diferently than the property editor.
>
>
> Many thanks
> Colin =^.^=
>
>
>
>
>
>
>



 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      26th Jun 2008
Well, the following shows a way to customise the title (there may be
simpler ways, but I can't see them). Obviously you'd need to put some
different code in around ".Text = " to put in some code (presumably
using reflection and GetGenericTypeDefinition() etc) to put in a more
useful name...

using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing.Design;
using System.Windows.Forms;

class CollectionEditor<T> : CollectionEditor
{
protected override CollectionForm CreateCollectionForm()
{
CollectionForm form = base.CreateCollectionForm();
form.Text = "Here be thee " + typeof(T).Name + "s";
return form;
}
public CollectionEditor() : base(typeof(T)) {}
}

class Foo
{
[Editor(typeof(CollectionEditor<Bar>), typeof(UITypeEditor))]
public Collection<Bar> Bars { get; private set; }

public Foo() {Bars = new Collection<Bar>();}
}
class Bar
{
public string Name { get; set; }
public int Age { get; set; }
}
static class Program
{
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form
{
Controls = {
new PropertyGrid {
Dock = DockStyle.Fill,
SelectedObject = new Foo()
}
}
});
}
}
 
Reply With Quote
 
colin
Guest
Posts: n/a
 
      26th Jun 2008
ok cool, thanks il give that a go, ive also been
trying to see what it uses by looking at
the .net reflector tool.

I did try and fool it giving it the type of the inner type

(i found it picks this type by looking for the type of the
Item property wich is the this[int index}

but giving the data as a list of wrappers, but although the title was
correct,
it complained it couldnt convert the items to the wrapper type
when it tried to save it.

I tried using converter, custom descriptor, and descriptor provider,
but it never seems to hit any of the functions that can be overiden
that i could use

Colin =^.^=

"Marc Gravell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Well, the following shows a way to customise the title (there may be
> simpler ways, but I can't see them). Obviously you'd need to put some
> different code in around ".Text = " to put in some code (presumably using
> reflection and GetGenericTypeDefinition() etc) to put in a more useful
> name...
>
> using System;
> using System.Collections.ObjectModel;
> using System.ComponentModel;
> using System.ComponentModel.Design;
> using System.Drawing.Design;
> using System.Windows.Forms;
>
> class CollectionEditor<T> : CollectionEditor
> {
> protected override CollectionForm CreateCollectionForm()
> {
> CollectionForm form = base.CreateCollectionForm();
> form.Text = "Here be thee " + typeof(T).Name + "s";
> return form;
> }
> public CollectionEditor() : base(typeof(T)) {}
> }
>
> class Foo
> {
> [Editor(typeof(CollectionEditor<Bar>), typeof(UITypeEditor))]
> public Collection<Bar> Bars { get; private set; }
>
> public Foo() {Bars = new Collection<Bar>();}
> }
> class Bar
> {
> public string Name { get; set; }
> public int Age { get; set; }
> }
> static class Program
> {
> [STAThread]
> static void Main()
> {
> Application.EnableVisualStyles();
> Application.Run(new Form
> {
> Controls = {
> new PropertyGrid {
> Dock = DockStyle.Fill,
> SelectedObject = new Foo()
> }
> }
> });
> }
> }



 
Reply With Quote
 
colin
Guest
Posts: n/a
 
      28th Jun 2008
well that does indeed set the title nicely,
however I doscovered you cant put template parameter inside attributes,

so this didnt work :-

public class UListWrap<T>
{
[Editor(typeof(UCollectionEditor<T>), typeof(UITypeEditor))]
// ^-- error CS0416:
// 'type parameter': an attribute argument cannot use type parameters
public class UDescWrap : CustomTypeDescriptor
{
UColection<T> data;
... GetProperties() etc ...
}
}

I cant avoid the generic becuase i cant see any other way of getting
the type name at the time CreateCollectionForm is called.

also the type of the object still apears as the typename of the wrapped
object
wich would be something like "UWrap'1"

oh and I also have to generate the generic type in reflection
(wich ive manged to do ok)
so i have no clue what T might be at run time.

I dont need to use any of this for simple types like int anyway,
but some of the items in some lists need to be able to get
the list of properties from the class that contains the list.

im thinking instead of using my own wrapper that I could use
typedescriptorprovider for each object in the list
isntead of aplying it to a type, wich aplies to al objects of that type.

interestingly i was looking at the arraycolectioneditor in reflector
and it uses a fairly simple wrapper like mine.

its just the type name that apears obscure thats driving me mad
and thats only in the pop up colection editor,
the rest works ok, am I just being too pedantic ?

many thanks again
Colin =^.^=

ps if i ever get this sorted il post the complete solution
somewhere like code project ...

"Marc Gravell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Well, the following shows a way to customise the title (there may be
> simpler ways, but I can't see them). Obviously you'd need to put some
> different code in around ".Text = " to put in some code (presumably using
> reflection and GetGenericTypeDefinition() etc) to put in a more useful
> name...
>
> using System;
> using System.Collections.ObjectModel;
> using System.ComponentModel;
> using System.ComponentModel.Design;
> using System.Drawing.Design;
> using System.Windows.Forms;
>
> class CollectionEditor<T> : CollectionEditor
> {
> protected override CollectionForm CreateCollectionForm()
> {
> CollectionForm form = base.CreateCollectionForm();
> form.Text = "Here be thee " + typeof(T).Name + "s";
> return form;
> }
> public CollectionEditor() : base(typeof(T)) {}
> }
>
> class Foo
> {
> [Editor(typeof(CollectionEditor<Bar>), typeof(UITypeEditor))]
> public Collection<Bar> Bars { get; private set; }
>
> public Foo() {Bars = new Collection<Bar>();}
> }
> class Bar
> {
> public string Name { get; set; }
> public int Age { get; set; }
> }
> static class Program
> {
> [STAThread]
> static void Main()
> {
> Application.EnableVisualStyles();
> Application.Run(new Form
> {
> Controls = {
> new PropertyGrid {
> Dock = DockStyle.Fill,
> SelectedObject = new Foo()
> }
> }
> });
> }
> }



 
Reply With Quote
 
Marc Gravell
Guest
Posts: n/a
 
      29th Jun 2008
Darn, you beat me to it... I was going to suggest
TypeDescriptionProvider ;-p

As for pedantic - well: it is your system; does the effort justify it?
Only you can answer that...

Marc
 
Reply With Quote
 
colin
Guest
Posts: n/a
 
      6th Jul 2008

"Marc Gravell" <(E-Mail Removed)> wrote in message
news:436c2f74-7669-4c0f-9a81-(E-Mail Removed)...
> Darn, you beat me to it... I was going to suggest
> TypeDescriptionProvider ;-p
>
> As for pedantic - well: it is your system; does the effort justify it?
> Only you can answer that...
>
> Marc


well the typedescriptorprovidor works for the pop up class but it breaks the
property window
i get null being passed to my MyPropertyDesripptor::getvalue(object
component)

as for being pedantic this has now become a challange of wits and
im not prepared to give in !!!

maybe the learning process may yeild some value.

thanks
Colin =^.^=


 
Reply With Quote
 
colin
Guest
Posts: n/a
 
      7th Jul 2008
I think i might of found a better way now,
I use type delegator wich wraps my array type
and overides GetElementType to return
another typedelegator wich wraps my element type
and overides Name to return the inner type.

im not sure how this extends to other collections yet,
or how useful it will be to use in place of a whole collection
of classes.

but it is just one class with a couple of simple functions.

Colin


"Marc Gravell" <(E-Mail Removed)> wrote in message
news:436c2f74-7669-4c0f-9a81-(E-Mail Removed)...
> Darn, you beat me to it... I was going to suggest
> TypeDescriptionProvider ;-p
>
> As for pedantic - well: it is your system; does the effort justify it?
> Only you can answer that...
>
> Marc



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change an Item Type Pepper Microsoft Outlook 1 3rd Sep 2008 02:53 AM
how do I change change the type of a dragged Item... aName Microsoft Dot NET Framework Forms 0 25th Sep 2006 09:33 PM
get the currently selected item in CollectionEditor? Henry J. Microsoft C# .NET 0 17th May 2006 04:02 AM
CollectionEditor item validation =?Utf-8?B?QnV6eiBCb25uZXI=?= Microsoft Dot NET 0 5th May 2005 05:11 PM
New mail doesn't display until I change from the selected item Patty Microsoft Outlook Installation 0 2nd Oct 2003 02:58 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:21 AM.