471,313 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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
Sep 25 '08 #1
5 2675
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
Sep 25 '08 #2
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
Sep 25 '08 #3
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<Timplementation 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
Sep 26 '08 #4
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
Sep 26 '08 #5
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
Sep 26 '08 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Guy Deprez | last post: by
3 posts views Thread by Daniel Lidström | last post: by
4 posts views Thread by anthony.wolfe | last post: by
reply views Thread by rosydwin | 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.