Follow up to last weeks user group - Corneliu’s Solution
I said last week I’d post Corneliu’s solution for all our “add an extra item to a data bound collection” woes. He emailed the code to me last week, but I thought I’d give it a whirl in the application we’re working on myself before I put it up here. I gave it a go today, and as any code you’d expect from a guy as bright as Corneliu, it works great.
I’ve got a C# version (by him) and a VB.NET conversion. It’s a little long to post the full files here, so here are the links:
ListControlNoneAdapter C# version
ListControlNoneAdapter Visual Basic .NET version
To make use of it, you’d do something like this:
protected override void OnLoad(EventArgs e){
   base.OnLoad(e);
   CustomerCollection customers = new CustomerCollection();
   customers.LoadAll();
 Â
   // Create an adapter to add the extra “None” item
   ListControlNoneAdapter adapter = new ListControlNoneAdapter();
   adapter.ListControl = customersCombo;
   adapter.NoneText = “(None)”;
   adapter.NoneValue = Guid.Empty;
   adapter.OriginalList = customers;
  Â
   // Bind to the adapter
   customersCombo.DisplayMember = “Name”;
   customersCombo.ValueMember = “CustomerID”;
   customersCombo.DataSource = adapter;
}
Thanks again Corneliu!
Also, if you don’t know who Corneliu is, make sure you come along to Code Camp!
Oh, and Coreneliu, get a blog!
Filed under: Uncategorized

Paul,
Thanks for the post and the nice words about me

I’ve been trying for couple of weeks already to start a blog, however the address I want to use belongs to some unknown Melbourne based company and I’m now struggling to buy it from them. However I got no reply. I’m not even sure if they exist as I could not even find them in Yellow/White pages.
So .. until further notice .. no blog.
Corneliu.
PS>> BTW, Where do you host this? What ISP are you using?