How to create an userdefined data source object

  • Thread starter Thread starter Norbert Pürringer
  • Start date Start date
N

Norbert Pürringer

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
 
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 CustomTypeDescriptor 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
 
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<T> for some T), or which calls over to the COM
object as rows are requested. Each has advantages and disadvantages.

Marc
 
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<T> for 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<T> implementation 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
 
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
 
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
 

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

Back
Top