You’ve probably heard a lot of talk about why you should
use Business Entities rather than DataSets. There are good
arguments for and against using Typed DataSets as Business Entities. And even very recently, there’s some people changing their minds on the issue.
I’m generally for the raw Business Entity
approach, typically from the business layer up, especially
when exposing data at the end of Web Services. Sahil
has promised to make me see the Typed DS light, but right now, I’ve
actually developed quite a bit of non-typed DataSet BE
objects in my framework. If you’re like me and gone down this
route, you may have found that once you get the hang of it, it’s not
too hard to DataBind your BEs to your UI controls. Then
you may have created some strongly-typed collections containing your
BEs, and naturally, you’ve needed to bind these collections to a
DataGrid, which is easy. So you’re really proud of yourself, and
you show your boss this great work, and they say to you…
“Great. Nice Grid. What happened to my sorting?”
You then you mumble something about how your collections aren’t
sortable, but they are better than DataSets nonetheless, because you
can add your own business logic to them easily, and they’re more
generic, and they might work better on the wire, and you look up
at them and with a blank stare they say to you…
“Great. Nice Grid. Um… What happened to my sorting again?”
So what are you gonna do? You could create a DataSet out of your Collection and pass that off to your Grid, but did someone say hack? You could add sorting to all of your collection objects, but did someone say tedious?
Do I have a perfect solution? No. But I do have a solution that
works pretty well for me, and lets me add sorting and filtering to my
DataGrid-bound BE collections. A few months back, I posted about
some code I’d worked on to allow Sort and Filter Strongly-Typed Collection Classes
Using this class is easy. Say you want to bind your strongly
typed collection to a DataGrid, and enable sorting and filtering.
Simply pass your collection class to the constructor of the
CollectionView, and bind your grid to the CollectionView instance
instead.
Like I said, I’ve been using it and it’s working
pretty well for me. I’ve recently added sorting and
filtering of child object’s properties, and some better handling of
null values. So without further ado, here’s the new download.
UPDATE - 7/25/05 - Jordan Bowness has translated the code into VB. You can download that file here. Thanks Jordan!
Enjoy!
-Brendan
Posted
Fri, Mar 18 2005 4:11 AM
by
Brendan Tompkins