|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Sortable, Bindable Object Collection?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 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 Why don't you use DataTable and DataView?
-- Show quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer To a tea you esteem a hurting back as a wallet. "DylanM" <Dyl***@discussions.microsoft.com> wrote in message news:1DD2307B-8D85-4E1D-9527-8BF90E211759@microsoft.com... > 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 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 Show quote "Kevin Spencer" wrote: > 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. > 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. -- Show quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer A brute awe as you, a Metallic hag entity, eat us. "DylanM" <Dyl***@discussions.microsoft.com> wrote in message news:2A74832C-BCF3-4845-B381-23BF7D304240@microsoft.com... >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 > > "Kevin Spencer" wrote: > >> 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. >> > 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 Show quote "Kevin Spencer" wrote: > 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. > > 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. -- Show quoteHTH, Kevin Spencer Microsoft MVP ..Net Developer A brute awe as you, a Metallic hag entity, eat us. "DylanM" <Dyl***@discussions.microsoft.com> wrote in message news:B700D0BF-F9C1-4210-BBDF-4D74DC5CB40A@microsoft.com... > 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 > > > "Kevin Spencer" wrote: > >> 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. >> >> > I managed to find some code by Brendan Tomkins that does exactly what I want,
a blog titled 'Sort and Filter Strongly-Typed collection Classes', located at http://codebetter.com/blogs/brendan.tompkins/archive/2004/09/02/24116.aspx I was nearly there, just hadn't set up my ListChangedEventHandler correctly. Thanks for your responses anyway. Show quote "Kevin Spencer" wrote: > 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. > |
|||||||||||||||||||||||