customized propertygrid

C

colin

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

colin

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

colin

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

colin

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

Marc Gravell

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
 
C

colin

Marc Gravell said:
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 =^.^=
 
M

Marc Gravell

I just need to add implemention for fields wich are themselves user defined

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
 
C

colin

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top