473,385 Members | 1,429 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 change the item type display name in pop up collectioneditor

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
7 3772
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
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
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Buzz Bonner | last post by:
Hi, I need to perform some validation on the items inserted into the CollectionEditor. How can I override the CollectionEditor OK button so that the editor doesn't close if a validation error is...
4
by: Richard Trahan | last post by:
(This is a repost -- the original got tucked away into an old thread because I used the same Subject name.) I'm trying to change the document title to add an asterisk when the document becomes...
3
by: Noozer | last post by:
I have several tags on a webpage of the same class. If the user clicks a specific checkbox I'd like to be able to alter the display property of the class, affecting all objects of that class. ...
3
by: Ronald S. Cook | last post by:
Hi all, I have an ASP.NET DataGrid wherein there is an edit link for each row. Upon clicking the link, certan fields in that row display in text boxes so that they may be edited. I would like...
13
by: nyt | last post by:
I have a problem of number and text field. I got the database file(mdb) that contains many combo boxes used and its list values are created by "value list" For eg field Field name= 'furniture'...
0
by: Henry J. | last post by:
Is there a way to find the element currently selected in a CollectionEditor where a collection is displayed? For PropertyGrid one can use something like SelectedGridItems to get the currently...
4
by: gregincolumbus | last post by:
I am trying to get the financial calculation on this to trigger whenever there is a change to select1. Right now, the user has to click on select2 to trigger the changes. Ideally, a change of...
0
by: =?Utf-8?B?TWlrZSBDb2xsaW5z?= | last post by:
I have a listview that when I select an item, it populates a details view. I want to show the item that was selected in the listview by changing it to yellow. Trouble is, the selected item does not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.