Data binding in Combo Box freezes form RRS feed

  • Question

  • Excuse my newbie-ness, but our company is moving into the .NET world and we are trying to use all the time saving features of Visual Studio 2008 / Visual Basic 2008 but Im having an issue with a data bound combo box.

    Here is the situation:

    Basic goal  - I have a Users table in SQL Sever 2005 which has as a foreign key into a Companies table that indicates which company the user is primarily associated with.
    I am creating a basic file maintenance screen that 1) on the load procedure, fills the combo box with all the Companies from the Company table 2) The combo box will show what company in that pre-filled combo box is currently in the Users table 3) Allow the user to change the Company with any of the other selections in the combo box. This is a simple task and will be used a thousand times in our project.

    What I did in Visual Studio - Using only the wizzard and setting properties on the control itself

    1) After dropping a Dataset on the form for the Users table (UsersDataSet), I noticed I forgot to include the Companies table, so dropped a second Dataset with the companies table (CompaniesDataSet). (So, I have two datsets to work with, which may or may not be an issue)

    2) Using the DataSource tab, I dragged a combobox from UsersDataSet onto the form that was bound to the field in the Users Table that holds the foreign key into the Companies table (which is referenced in the CompaniesDataSet)

    3) I set the following properties on the Combobox:

            Data Set : CompaniesBindingSource
            Display Member : Company_Name (in the Company Table)
            Value Member: Company_ID (in the Company Table)
            Selected Value: UsersBindingSource - user_profile_primary_company (which in the database is a foreign key to Company_ID in Companies)

    When I run the code, all companies names show in the combobox, but whenever I click into it, the box is highlighted blue and the whole form is frozen and I cant click out.

    Please help me on this if you can, or let me know if you need more info (I am a little verbose, so I prob over explained the basic issue)

    Another question - do all these wizzards that are supposed to save time and coding actually make finding the errors involved more difficult than hand-coding every control on the form (this particular table produces more than 75 controls (mostly check boxes)) We hired someone knowledgable in FoxPro and VB 6 and I believe he is fighting the wizzard because he doesnt know how it works and he wants to hand code every control (if we did that, our project will last years)

    Thanks in advance.
    Monday, July 28, 2008 9:05 PM


  • Hello kdogg

    Verbose is good...terse is not

    And you made a very astute observation about the side affects of using the wizards.  There is always extra baggage associated with the wizards and how they implement things.

    I am a string advocate of seperating data operations from from user interface operations.  The wizards tend to encourage tightly tieing the two together. 

    My preference is to avoid the wizards, Datasets and DataAdapters like the plague in a winforms environment. And I never use the datasets for handling Updates.   If you application is going to involve a lot of concurrent updating from several clients and you can live last update wins type of environment then you might get by. 

    But if you need a tight reign on concurrency and perhaps implement two phase commits you are going to have problems.

    In your case, try SeletectedItem instead of SelectedValue for the UsersBindingSource.  See if that frees things up a bit


    Wednesday, July 30, 2008 4:10 AM