How to create an userdefined data source object

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?ISO-8859-1?Q?Norbert_P=FCrringer?=

    #1

    How to create an userdefined data source object

    Hello,

    does anyone have for me a sample how to create an object, which has
    access to any form of data and can be used as a data source for data
    bound data grids.

    In my case I've got a com object (GRecordset) which should become a
    data source for a data grid.

    Thank you,
    Norbert
  • Marc Gravell

    #2
    Re: How to create an userdefined data source object

    For grids, the key thing is that the type should implement IList (or
    IListSource, which provides indirect access to an IList), and ideally
    the list should have a typed indexer (i.e. public SomeType this[int]
    {get;}). That is enough for most common binding scenarios.

    When things get more complex, it is possible to go deeper, using
    ITypedList, or by implementing a CustomTypeDescr iptor for the row-type
    (SomeType in the above) - but the first thing to try is just implement
    IList (or IListSource) on the collection-like object.

    Marc

    Comment

    • Marc Gravell

      #3
      Re: How to create an userdefined data source object

      For info, in the case of a COM object, I would expect that you need to
      write a wrapper object that implements IList, and either reads the data
      into a local copy (List<Tfor some T), or which calls over to the COM
      object as rows are requested. Each has advantages and disadvantages.

      Marc

      Comment

      • =?ISO-8859-1?Q?Norbert_P=FCrringer?=

        #4
        Re: How to create an userdefined data source object

        Hello
        For info, in the case of a COM object, I would expect that you need to
        write a wrapper object that implements IList, and either reads the data
        into a local copy (List<Tfor some T), or which calls over to the COM
        object as rows are requested.
        this COM object called GRecordset (which looks like a DAO database
        object) is not only for reading data. There are functions to write
        data back. A List<Timplement ation would only be a read-only data
        structure. Do you have an idea how to implement a read/write data
        structure to be used as data source for a data grid? What about the
        DataSet object in C#? That would be the right data structure for a
        data grid to show and save data. But how could I combine the
        GRecordset with a C#- DataSet?

        Thank you,
        Norbert

        Comment

        • Marc Gravell

          #5
          Re: How to create an userdefined data source object

          I'm assuming that the GRecordset can have arbitrary columns?

          In which case, it is one of the trickier scenarios; to enable direct
          binding you'd have to implement a range of interfaces such as the tricky
          ITypedList, and probably most of IBindingList etc. Not trivial, even if
          you have done lots of ComponentModel work.

          I would suggest that a more pragmatic approach might be to read your
          data out of the GRecordset into a DataTable (just in a loop etc). Bind
          to the DataTable; and when you are done, do the same thing in reverse to
          copy the DataTable contents back over the GRecordset. Or *maybe* you
          could go halfway by using events on the DataTable to perform updates as
          they happen...

          Marc

          Comment

          • Marc Gravell

            #6
            Re: How to create an userdefined data source object

            I wrote a demo for this on the train - not using GRecordset
            specifically, but just a bespoke non-bindable table implementation, to
            show how to wrap it in ITypedList etc. It is too long for this forum,
            so I've e-mailed you instead. If you have a different address, e-mail
            me back with alternative details.

            Marc

            Comment

            Working...