471,337 Members | 912 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,337 software developers and data experts.

customized propertygrid

Hi,
I thought I could use the property grid to nicly
edit some of my data, however it seems to require each field to be a
property,
wich I didnt realise was implied in the name of it lol.

Is there a way to customize it so it can display and edit fields wich
are stored in a dictionary ?

the classes I have is basically a custom/user defined class,
where theres a list of allowable fields with type info read from a file,
and a list of actual fields wich have data in them wich are read from a
file,
and a list of defualt values, the list also contains information such as
group name etc..

It would be nice to distinguish fields wich have data other than defualt in
them.

Ive tried to work out how to custiomise it using the AddTabType
but it seems like it still requires property fields.

many thanks
Colin =^.^=
Jun 27 '08 #1
8 4682
Basically, you can do this by writing a custom property model - here
is an example:

http://groups.google.co.uk/group/mic...ea254ad3c6abf6

You can use either ICustomTypeDescriptor or TypeDescriptionProvider to
implement this, and many, many things are possible. So please let me
know if you want more info, as it is an area that I can talk on in
quite depressing depth...

Marc
Jun 27 '08 #2
thanks,
it looks quite complicated and involved,
almost as difficult as writing a custom control,
actually I think what I might do is look into custom classes
and build a class with the properties and all the tags,
possibly even as a wrapper,
this might be useful when/if I come to work out what I need to
do to actually use them anyway.

I havnt used custom classes yet, ive only heard them mentioned,
but I might instead generate a c# file and compile it at runtime
and probably insert those back into the project on the next build.

Colin =^.^=

"Marc Gravell" <ma**********@gmail.comwrote in message
news:1e**********************************@k37g2000 hsf.googlegroups.com...
Basically, you can do this by writing a custom property model - here
is an example:

http://groups.google.co.uk/group/mic...ea254ad3c6abf6

You can use either ICustomTypeDescriptor or TypeDescriptionProvider to
implement this, and many, many things are possible. So please let me
know if you want more info, as it is an area that I can talk on in
quite depressing depth...

Marc

Jun 27 '08 #3
Ive written an implementation for CustomTypeDescriptor
and PropertyDescriptor, wich pick up the neccessary information from my
files,
but im not sure how to now use this with the propertygrid ?

I seem to end up wadding thru tons of waffle for property grid,
and I cant see where you use it in the example you gave

many thanks
Colin =^.^=

"Marc Gravell" <ma**********@gmail.comwrote in message
news:1e**********************************@k37g2000 hsf.googlegroups.com...
Basically, you can do this by writing a custom property model - here
is an example:

http://groups.google.co.uk/group/mic...ea254ad3c6abf6

You can use either ICustomTypeDescriptor or TypeDescriptionProvider to
implement this, and many, many things are possible. So please let me
know if you want more info, as it is an area that I can talk on in
quite depressing depth...

Marc

Jun 27 '08 #4
aha ok forget that it was so simple, I just pass a CustomTypeDescriptor
into the selected object instead of the actual object.
I chose to keep this seperate from the object.

It works now, but I would like to be able to indicate if
the data is different from the defualt value,
I gues il see if theres a way to change the background colour or something.

thanks
Colin =^.^=
"colin" <co*********@ntworld.NOSPAM.comwrote in message
news:w%****************@newsfe1-win.ntli.net...
Ive written an implementation for CustomTypeDescriptor
and PropertyDescriptor, wich pick up the neccessary information from my
files,
but im not sure how to now use this with the propertygrid ?

I seem to end up wadding thru tons of waffle for property grid,
and I cant see where you use it in the example you gave

many thanks
Colin =^.^=

"Marc Gravell" <ma**********@gmail.comwrote in message
news:1e**********************************@k37g2000 hsf.googlegroups.com...
>Basically, you can do this by writing a custom property model - here
is an example:

http://groups.google.co.uk/group/mic...ea254ad3c6abf6

You can use either ICustomTypeDescriptor or TypeDescriptionProvider to
implement this, and many, many things are possible. So please let me
know if you want more info, as it is an area that I can talk on in
quite depressing depth...

Marc


Jun 27 '08 #5
Sorry for delay... weekend etc...

I've answered the default thing on your other thread.

Re the usage; you would normally give the object itself to the
PropertyGrid, although a facade is fine too...

Basically, PropertyGrid gets its values by calling
TypeDescriptor.GetProperties(yourObject);

You can influence what TypeDescriptor returns in two ways; if your
object itself implements ICustomTypeDescriptor, then it will use this;
this approach is useful if the properties change instance-by-instance
(such as with a DataTable / DataRowView). Alternatively; if the
properties are the same for all instances of the type, you can move
this out of the type by using a TypeDescriptionProvider and
associating that with the type (either through an attribute or a
call). For example, in one of my systems the "extended" values (key/
value pairs) are the same per type - i.e. every Customer has the same
set of extended values - so I use TypeDescriptionProvider.

What you have done is provide a "facade" - i.e. a *separate* object
that you give the grid instead of your actual object. This is also a
valid choice, but it might be harder to bind to some other controls.

If you can describe the setup a bit more I can probably knock up a
pretty complete example in either instance/type syntax...

Marc
Jun 27 '08 #6
"Marc Gravell" <ma**********@gmail.comwrote in message
news:01**********************************@u69g2000 hse.googlegroups.com...
Sorry for delay... weekend etc...

I've answered the default thing on your other thread.

Re the usage; you would normally give the object itself to the
PropertyGrid, although a facade is fine too...

Basically, PropertyGrid gets its values by calling
TypeDescriptor.GetProperties(yourObject);

You can influence what TypeDescriptor returns in two ways; if your
object itself implements ICustomTypeDescriptor, then it will use this;
this approach is useful if the properties change instance-by-instance
(such as with a DataTable / DataRowView). Alternatively; if the
properties are the same for all instances of the type, you can move
this out of the type by using a TypeDescriptionProvider and
associating that with the type (either through an attribute or a
call). For example, in one of my systems the "extended" values (key/
value pairs) are the same per type - i.e. every Customer has the same
set of extended values - so I use TypeDescriptionProvider.

What you have done is provide a "facade" - i.e. a *separate* object
that you give the grid instead of your actual object. This is also a
valid choice, but it might be harder to bind to some other controls.

If you can describe the setup a bit more I can probably knock up a
pretty complete example in either instance/type syntax...

Marc
thanks very much for your help, its been a bit confusing but
ive learned enough to get it to do what I want :)

I just need to add implemention for fields wich are themselves user defined
structs,
such as vectors wich are 3 floats x,y,z.
ive seen references as to how to do this.

basically the classes are not c# but a custom script language,
the non defualt fields are stored in the file
and theres a definition of the class in the file
and the user can create new classes.
I just store the field data in a dictionary for each object
and a similar dictionary for the field definitions.

the propertygrid seemed better than using a data grid,
especially as there are already catagory definitions.
the files are part of a 3d game, i was hoping to not clutter up the
objects classes so they look close to the definitions.

I also need to edit a large amount of complicated data,
and I find the data grid very slow for large data sets.

maybe one day il make my own cell based data editor.

Colin =^.^=
Jun 27 '08 #7
I just need to add implemention for fields wich are themselves user defined
structs,
Typically, you would implement your own TypeConverter, marking the
struct with TypeConverterAttribute (to associate it), and override
GetProperties and GetPropertiesSupported (return true) to provide the
custom properties. Since structs should generally be immutable, you
would also override GetCreateInstanceSupported (return true) and
CreateInstance - these last two are necessary to make the properties
pseudo-editable; in fact, it will use CreateInstance to create a *new*
struct to assign to the container's property.

I can provide an example if you need, but I'm at the MSDN roadshow
(Cardiff) tomorrow, so it would have to wait until Tuesday ;-p

Marc
Jun 27 '08 #8
thanks,
Ive managed to get the custom structs working
with expanded fields getting edited and created if necessary.

I decided to combine everything into one class,
wich implements the ICustomTypeDescriptor interface
and inherits PropertyDescriptor, and has ExpandableObjectConverter as a
typeconverter attribute.

I was dubious this would actually work but it seems to.
it saved a lot of shared data and/or function calls from one to the other.

I now need to do the same for a few of the custom structs wich are actually
implemented as ordinary structs, this would involve some reflection.

the custom structs are just simply implmented as dictionary<name,object>
so its easy to look up the field by name and get the data wich may also be
another dictionary.
I might look into using the internal custom struct to see if it could mean
sharing the code with the reflection.

Colin =^.^=
"Marc Gravell" <ma**********@gmail.comwrote in message
news:01**********************************@l64g2000 hse.googlegroups.com...
>I just need to add implemention for fields wich are themselves user
defined
structs,

Typically, you would implement your own TypeConverter, marking the
struct with TypeConverterAttribute (to associate it), and override
GetProperties and GetPropertiesSupported (return true) to provide the
custom properties. Since structs should generally be immutable, you
would also override GetCreateInstanceSupported (return true) and
CreateInstance - these last two are necessary to make the properties
pseudo-editable; in fact, it will use CreateInstance to create a *new*
struct to assign to the container's property.

I can provide an example if you need, but I'm at the MSDN roadshow
(Cardiff) tomorrow, so it would have to wait until Tuesday ;-p

Marc

Jun 27 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Terry | last post: by
3 posts views Thread by Dave Girvitz | last post: by
1 post views Thread by ANDRES BECERRA | last post: by
1 post views Thread by Lance | last post: by
6 posts views Thread by Steve Teeples | last post: by
4 posts views Thread by phcmi | last post: by
3 posts views Thread by =?Utf-8?B?U3RldmVU?= | last post: by

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.