Monday, January 10, 2005

Use BindingList for data bound collections

I finished up another chapter on my book last night. This one was on creating data bound custom business objects and collections. I won't try to reiterate the entire chapter here, but I will pass along one of the key take-aways: use BindingList<T> for custom business object collections if you want to provide rich data binding capabilities in Windows Forms 2.0.

The BindingList<T> generic type is defined in the System.ComponentModel.Collections.Generics namespace in Beta 1, but is getting refactored into System.ComponentModel in Beta 2. Basically this type allows you to create strongly typed collections that implement IBindingList (partially), IList, ICollection, and IEnumerable, with a single line of code:

BindingList<Customer> CustomerCollection = new BindingList<Customer>();

By doing just this, you get a collection that works fine with both Windows Forms and ASP.NET data binding mechanisms, including two-way data binding (presentation and editing) support in Windows Forms, and also will fire ListChanged events whenever items in the collection are added, removed, or replaced. If you want to support events when the contained objects are edited, you will need to implement the INotifyPropertyChanged interface on the object type definition itself (this interface is named IPropertyChanged in Beta 1).

Additionally, if you want to support sorting and searching on the collection, all it takes it to derive a class from your BindingList<T> parameterized type, and override a few base class methods and properties. For example, you could declare a Customer collection and provide searching capability with something like the following:

public class CustomerCollection : BindingList<Customer>
{
   protected override bool SupportsSearchingCore { get { return true; } }

   protected override int FindCore(PropertyDescriptor property, object key)
   {
      for (int i = 0; i < Count; i++)
      {
            Customer c = this[i];
          if (property.GetValue(c) == key)
          {
              return i;
          }
      }
      return -1; // Not found
  
}
}

Very powerful stuff. Sorting is a little more involved, but follows the same process. Override the sort related properties, and provide a sorting algorithm in the ApplySortCore override and you are off and running.

So much easier and more powerful than the old derive from CollectionBase approach. You get type safety, alot of additional functionality, and the efficiency of generic types.



.NET | Languages and Tools

Monday, January 10, 2005 4:09:21 PM (GMT Standard Time, UTC+00:00)
Comments [3]  |  Related posts:
DevConnections Orlando Slides and Demos
Developing Applications with Windows Workflow Foundation LiveLesson
Slides and demos from Cleveland .NET SIG
Silverlight - not just pretty graphics - Cross platform .NET Framework!
Great guidance on using Team Foundation Server for your projects
DevConnections Orlando - a tale of three sessions
Tracked by:
"adipex" (adipex) [Trackback]
"slot machines" (slot machines) [Trackback]
"casino games" (casino games) [Trackback]
"casino" (casino) [Trackback]
"slot machines" (slot machines) [Trackback]
"good forex trading systems" (forex trading systems) [Trackback]
"freeware texas holdem" (freeware texas holdem) [Trackback]
"Online Games poker" (Online Games poker) [Trackback]
"viagra" (viagra) [Trackback]
"online casinos" (online casinos) [Trackback]
"online casinos" (online casinos) [Trackback]
"casino on net" (casino on net) [Trackback]
"cash advance" (cash advance) [Trackback]
"online casino game com" (online casino game com) [Trackback]
"online betting casinos" (online betting casinos) [Trackback]
"Free Downloadable Poker" (Free Downloadable Poker) [Trackback]
"free slot machine software" (free slot machine software) [Trackback]
"pet prescriptions online" (pet prescriptions online) [Trackback]
"slot machines" (slot machines) [Trackback]
"ganancias casinos portales internet" (ganancias casinos portales internet) [Trackback]
"best online sports casino to bet" (best online sports casino to bet) [Trackback]
"texas holdem poker rule" (texas holdem poker rule) [Trackback]
"online blackjack" (online blackjack) [Trackback]
"phentermine online" (phentermine online) [Trackback]
"juego gratis linea" (juego gratis linea) [Trackback]
"spielautomat" (spielautomat) [Trackback]
"black casino jack online poker video" (black casino jack online poker video) [Trackback]
"effective diet pill" (effective diet pill) [Trackback]
"ambien cheapest consultation free online pharmacy" (ambien cheapest consultatio... [Trackback]
"tamiflu purchase" (tamiflu purchase) [Trackback]
"palm 505 download texas holdem free" (palm 505 download texas holdem free) [Trackback]
"progressive slot machines" (progressive slot machines) [Trackback]
"cash advance" (cash advance) [Trackback]
"low carb diet pills" (low carb diet pills) [Trackback]
"online pharmacy without percsription" (online pharmacy without percsription) [Trackback]
"no deposit online casino coupon codes" (no deposit online casino coupon codes) [Trackback]
"texas holdem secrets" (texas holdem secrets) [Trackback]
"jo.hawaiicity.com link online phentermine" (jo.hawaiicity.com link online phent... [Trackback]
"forex course trading" (forex course trading) [Trackback]
"dish network" (dish network) [Trackback]
"neteller online casinos" (neteller online casinos) [Trackback]
"856" (856) [Trackback]
"1936" (1936) [Trackback]
"hot housewives" (hot housewives) [Trackback]
"freeware keno games" (freeware keno games) [Trackback]
"soma" (soma) [Trackback]
"butalbital" (butalbital) [Trackback]
"didrex" (didrex) [Trackback]
"alprazolam" (alprazolam) [Trackback]
"hydrocodone online" (hydrocodone online) [Trackback]
"casino black jack" (casino black jack) [Trackback]
"document management" (document management) [Trackback]
"pharmacies online" (pharmacies online) [Trackback]
"buy soma" (buy soma) [Trackback]
"buy cipro" (buy cipro) [Trackback]
"generic butalbital" (generic butalbital) [Trackback]
"sandia casino" (sandia casino) [Trackback]


Wednesday, January 19, 2005 8:29:12 PM (GMT Standard Time, UTC+00:00)
It's nice t see some refactoring and generics. But this is not a new revolution brought by 2.0. We had throughly exploited IBindingList interface which is same thing in exactly the same way in 1.x.
Monday, May 09, 2005 7:44:30 AM (GMT Standard Time, UTC+00:00)
In your free time, check some information about free no download slots http://www.juris-net.com/free-no-download-slots.html
poker tournament http://www.juris-net.com/poker-tournament.html
biloxi mississippi casinos http://www.juris-net.com/biloxi-mississippi-casinos.html
blackjack lessons http://www.juris-net.com/blackjack-lessons.html
blackjack software download http://www.juris-net.com/blackjack-software-download.html
500 poker chip set http://www.juris-net.com/500-poker-chip-set.html
san manuel casino http://www.juris-net.com/san-manuel-casino.html
gambling tips http://www.juris-net.com/gambling-tips.html
excalibur hotel casino http://www.juris-net.com/excalibur-hotel-casino.html
las vegas slot machines http://www.juris-net.com/las-vegas-slot-machines.html
first class online casinos http://www.juris-net.com/first-class-online-casinos.html
casino party business opportunity http://www.juris-net.com/casino-party-business-opportunity.html
craps table to buy http://www.juris-net.com/craps-table-to-buy.html
1000 clay poker chips royal flush http://www.juris-net.com/1000-clay-poker-chips-royal-flush.html
free casino slot http://www.juris-net.com/free-casino-slot.html
slot tokens http://www.juris-net.com/slot-tokens.html
buckaroo black jack http://www.juris-net.com/buckaroo-black-jack.html
restaurant economic development gambling http://www.juris-net.com/restaurant-economic-development-gambling.html
rules for casino craps http://www.juris-net.com/rules-for-casino-craps.html
games blackjack adult free http://www.juris-net.com/games-blackjack-adult-free.html
journals on pros and cons of gambling http://www.juris-net.com/journals-on-pros-and-cons-of-gambling.html
blackjack book http://www.juris-net.com/blackjack-book.html
roulette game toy http://www.juris-net.com/roulette-game-toy.html
secret to winning at back to back keno slot machine http://www.juris-net.com/secret-to-winning-at-back-to-back-keno-slot-machine.html
full version blackjack elf http://www.juris-net.com/full-version-blackjack-elf.html
blackjack counting books http://www.juris-net.com/blackjack-counting-books.html
blackjack software no ads http://www.juris-net.com/blackjack-software-no-ads.html
craps table odds http://www.juris-net.com/craps-table-odds.html
roulette free system of dozens http://www.juris-net.com/roulette-free-system-of-dozens.html
dice setting craps http://www.juris-net.com/dice-setting-craps.html
keno board http://www.juris-net.com/keno-board.html
14017 chip roulette wheel http://www.juris-net.com/14017-chip-roulette-wheel.html
keno game http://www.juris-net.com/keno-game.html
keno wheeling systems http://www.juris-net.com/keno-wheeling-systems.html
win keno http://www.juris-net.com/win-keno.html
... Thanks!!!
Tuesday, September 27, 2005 5:21:36 AM (GMT Standard Time, UTC+00:00)
Cheap Viagra
Comments are closed.



















Sign In
Copyright © 2006-2007 Brian Noyes. All rights reserved.
designed by NUKEATION STUDIOS