By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,418 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,418 IT Pros & Developers. It's quick & easy.

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

P: n/a
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<Vectorcollection;

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 =^.^=



Jun 27 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
oops that shoud of been

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

public class UWrapper<T>
{
}

UCollection<UWrapper<Vector>collection;

"colin" <co*********@ntworld.NOSPAM.comwrote in message
news:Nm*******************@newsfe30.ams2...
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<Vectorcollection;

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 =^.^=



Jun 27 '08 #2

P: n/a
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<BarBars { 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()
}
}
});
}
}
Jun 27 '08 #3

P: n/a
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" <ma**********@gmail.comwrote in message
news:ez**************@TK2MSFTNGP04.phx.gbl...
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<BarBars { 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()
}
}
});
}
}

Jun 27 '08 #4

P: n/a
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<Tdata;
... 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" <ma**********@gmail.comwrote in message
news:ez**************@TK2MSFTNGP04.phx.gbl...
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<BarBars { 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()
}
}
});
}
}

Jun 28 '08 #5

P: n/a
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
Jun 29 '08 #6

P: n/a

"Marc Gravell" <ma**********@gmail.comwrote in message
news:43**********************************@m45g2000 hsb.googlegroups.com...
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 =^.^=
Jul 6 '08 #7

P: n/a
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" <ma**********@gmail.comwrote in message
news:43**********************************@m45g2000 hsb.googlegroups.com...
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

Jul 7 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.