customized propertygrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • colin

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


  • Marc Gravell

    #2
    Re: customized propertygrid

    Basically, you can do this by writing a custom property model - here
    is an example:



    You can use either ICustomTypeDesc riptor or TypeDescription Provider 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

    Comment

    • colin

      #3
      Re: customized propertygrid

      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" <marc.gravell@g mail.comwrote in message
      news:1ea59c6e-0044-4571-9138-f22ae79c5a43@k3 7g2000hsf.googl egroups.com...
      Basically, you can do this by writing a custom property model - here
      is an example:
      >

      >
      You can use either ICustomTypeDesc riptor or TypeDescription Provider 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

      Comment

      • colin

        #4
        Re: customized propertygrid

        Ive written an implementation for CustomTypeDescr iptor
        and PropertyDescrip tor, 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" <marc.gravell@g mail.comwrote in message
        news:1ea59c6e-0044-4571-9138-f22ae79c5a43@k3 7g2000hsf.googl egroups.com...
        Basically, you can do this by writing a custom property model - here
        is an example:
        >

        >
        You can use either ICustomTypeDesc riptor or TypeDescription Provider 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

        Comment

        • colin

          #5
          Re: customized propertygrid

          aha ok forget that it was so simple, I just pass a CustomTypeDescr iptor
          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" <colin.rowe1@nt world.NOSPAM.co mwrote in message
          news:w%mOj.9963 $DQ3.701@newsfe 1-win.ntli.net...
          Ive written an implementation for CustomTypeDescr iptor
          and PropertyDescrip tor, 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" <marc.gravell@g mail.comwrote in message
          news:1ea59c6e-0044-4571-9138-f22ae79c5a43@k3 7g2000hsf.googl egroups.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 ICustomTypeDesc riptor or TypeDescription Provider 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
          >
          >

          Comment

          • Marc Gravell

            #6
            Re: customized propertygrid

            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(y ourObject);

            You can influence what TypeDescriptor returns in two ways; if your
            object itself implements ICustomTypeDesc riptor, 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 TypeDescription Provider 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 TypeDescription Provider.

            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

            Comment

            • colin

              #7
              Re: customized propertygrid

              "Marc Gravell" <marc.gravell@g mail.comwrote in message
              news:01421bbf-b87c-453c-8052-615d99e6769f@u6 9g2000hse.googl egroups.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(y ourObject);
              >
              You can influence what TypeDescriptor returns in two ways; if your
              object itself implements ICustomTypeDesc riptor, 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 TypeDescription Provider 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 TypeDescription Provider.
              >
              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 =^.^=


              Comment

              • Marc Gravell

                #8
                Re: customized propertygrid

                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 TypeConverterAt tribute (to associate it), and override
                GetProperties and GetPropertiesSu pported (return true) to provide the
                custom properties. Since structs should generally be immutable, you
                would also override GetCreateInstan ceSupported (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

                Comment

                • colin

                  #9
                  Re: customized propertygrid

                  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 ICustomTypeDesc riptor interface
                  and inherits PropertyDescrip tor, and has ExpandableObjec tConverter 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" <marc.gravell@g mail.comwrote in message
                  news:01844917-ac12-4c53-b62e-b4eea671b4e4@l6 4g2000hse.googl egroups.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 TypeConverterAt tribute (to associate it), and override
                  GetProperties and GetPropertiesSu pported (return true) to provide the
                  custom properties. Since structs should generally be immutable, you
                  would also override GetCreateInstan ceSupported (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

                  Comment

                  Working...