XMLpitstop.com   |  VBnetexpert.com   |  Community Credit  
 
 
Pitstop Search:  
in
 
Sign in | Join | Help
 
 
  Blog
    Home  
 
  Entries By Date
 
<August 2009>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
 
 
  Blog Categories
   
 
  Archives
    December 2009 (2)  
    October 2009 (1)  
    September 2009 (1)  
    August 2009 (2)  
    July 2009 (2)  
    June 2009 (1)  
    May 2009 (1)  
    February 2009 (1)  
    December 2008 (1)  
    November 2008 (3)  
    September 2008 (3)  
    August 2008 (3)  
    June 2008 (4)  
    May 2008 (2)  
    April 2008 (3)  
    March 2008 (3)  
    February 2008 (5)  
    December 2007 (4)  
    November 2007 (1)  
    October 2007 (3)  
 
  Syndication
    RSS  
    Atom  
    Comments RSS  
  .NET Flea Market  
 

Falling Behind the Times

The other day I was writing some code and I got an error message.  It happened to be one of those cases where it should have worked.  You know when good code it written it just happens to work like you expect it to.  The general idea was:

    Private Sub FillCombos()
        Dim dict As New Dictionary(Of String, String)
        With dict
            .Add("Steve", "Steve Harris")
            .Add("Bill", "Bill Murray")
            .Add("Dave", "Dave's not here")
            .Add("Jack", " (Captain) Jack Sparrow")
        End With

        ComboBox1.DataSource = dict.Keys
        ComboBox2.DataSource = dict.Values

    End Sub

Seems pretty logical.  The Keys property of a dictionary is a collection and so is the Values.  A collection is just a list of things.  They should be bindable, right?  Well, no.  The error you get is: “Complex DataBinding accepts as a data source either an IList or an IListSource.”  And after poking around, it’s right.  The collections do not implement those interfaces.

So that was going to be a blog topic about how and why those collections couldn’t be databound, but when I tried it on my other computer, I noticed that I had extra methods on those collections, ToArray being one of them.  so I used ToArray and the databinding worked.  As it turns out, the ToArray was added from System.Linq.Enumerable, which comes along with .NET 3.0.  I switched the project to .NET 2.0 and the ToArray function disappeared.

So now, I’m blogging more about the blunt realization that I’m officially missing out on additional functionality that would have simplified my code.  Well, as complicated as this solution makes it:

ComboBox1.DataSource = New Generic.List(Of String)(dict.Keys)
ComboBox2.DataSource = New Generic.List(Of String)(dict.Values)

So, with the release of Windows 7, I do plan on installing VS 2008 at work and driving ahead with 64-bit development under .NET 3.5.  Well, eventually.  There’s still some Win2k workstations out there…

Comments

No Comments

About anachostic

That's me. Seek and ye shall find.
 
 
Copyright © . All Rights Reserved.
Powered by Community Server (Commercial Edition), by Telligent Systems