Sortable, Bindable Object Collection?

G

Guest

Hi,

I'm trying to create a collection class that I can bind to DataGrids (In
particular, we use the C1.TrueDBGrid from Component One)

I'm inheriting ArrayList and implementing IBindingList & ITypedList. I'm
pretty much there, data binding is fine & the underlying objects in the
collection are being updated by the grid - where I'm struggling is with the
sorting functionality. At the moment, the column I am clicking on is being
sorted but nothing else in the grid is!

Also, when I click on the column header again to switch the sort direction
it does not immediately apply, I have to move off the column then back again
to be able to change sort direction.

What I want is my collection to behave like a DataTable\View. All data in
the grid should of course be sorted to reflect the column being sorted.
DataTable sorting also applies additional sorting, eg; my grid exposes
columns Qty1, Qty2, Qty3. If I chose to sort by Qty1 it would sort primarily
by that column, then by Qty2, then by Qty3 etc. I guess that DataTable
achieves this by using the DataColumnCollection to determine columns to sort
by? I would need something similar for my collection to be able work out
which addition fields to sort by?

I've found various articles on DataBinding collections, sorting collections
- but can anyone point me towards articles \ examples addressing these
described issues?

Thanks
 
G

Guest

Sorry, I lied!

The rest of the data in the grid IS being sorted, it's just the grid isn't
immediately reflecting the new sort order for all of the data - only for the
column that was clicked. If I begin scrolling through records, the values in
the grid change to display the new order.

I guess I need to raise an event to inform the grid to repaint \ rebind?

Thanks
 
K

Kevin Spencer

Why don't you use DataTable and DataView?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
To a tea you esteem
a hurting back as a wallet.
 
G

Guest

I only ever use System.Data objects within my DAL, they are not passed back
through the tiers. I strictly work with business objects, so need a
collection object that can be bound, edited, sorted etc. It's a bit more
work, but I much prefer the abstraction and eventual GUI code.

Manually firing off a grid.Refresh in the grids 'AfterSort' event actually
solves my problems, but I was kind of hoping to wire this into the collection
class. Must be possible to inform the grid that it needs to do a refresh,
since this is what happens when using a DataTable.

Cheers
 
K

Kevin Spencer

A DataTable or a DataView is not necessarily a DAL object at all. You're
limiting yourself with preconceptions. A DataTable is a disconnected entity,
and does not even need to be used in conjunction with a database. I have
used them for all sorts of things. Don't let the "Data" in the name confuse
you. Everything is either Data or Process.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
 
G

Guest

Sure - but this particular grid is probably the most important part of the
application, it performs an allocation of stock and depending on the current
status I have to apply complex styling to the grid. It makes more sense to be
to work with a collection of my 'Allocation' objects that already have most
of the logic built in then to bind to a DataTable and have to write the logic
again in the GUI
 
K

Kevin Spencer

In that case, why not create your own set of classes that you can use the
DataTable/DataView object model as a model for? Just use what you need,
discard the rest, and add whatever else you need.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
 

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

Top