Problem with “data bound ComboBox” with “Visual Basic 2005”

It seems that there is a problem with “data bound ComboBox” with “Visual Basic 2005”

Please try this…

(I used SQL 2005 Express for database.)

Create a new Windows Application.

Add a new database named “ComputerUsers.mdf”

In the DataSource Configuration Wizard, click cancel (since there’s no table yet)

In Server Explorer, create two tables Users and UserTypes with the following definitions:

Users table

FirstName varchar(50) notnull

LastName varchar(50) notnull

UserType int notnull

UserTypes table

UserTypeId int notnull primaryKey

UserTypeName varchar(50) notnull


In the Diagram, add the two tables, then drag the UserType field of Users table to UserTypeId field of UserTypes table.

This will create a relation FK_Users_UserTypes with

Primary key UserTypes-UserTypeId

Foreign key User-UserType

Save the diagram.


Fill the UserTypes table (using Server Explorer):

UserTypeID UserTypeName

1 Programmer

2 Project Manager

3 Department Manager

4 Program Manager

5 Lab Director


In the Data Source, click “Add New Data Source”, select ComputerUsers.mdf and check the “tables check box” to include the two tables in the new ComputerUsersDataSet.

The “Data Sources” now displays ComputerUsersDataSet with the two tables Users & UserTypes.

Select “Form1.vb [Design]” and select back “Data Sources”.

Expand (click the +) Users table to display the fields.

Click on the UserType field, click again on the dropdown and select “ComboBox”

In the Users table dropdown, select Details.


Then drag the Users table onto “Form1.vb [Design]”.

This created the following:

  1. two textboxes for FirstName and LastName
  2. a ComboBox for UserType field
  3. the corresponding labels
  4. ComputerUsersDataSet, UsersBindingSource, UsersTableAdapter and UsersBindingNavigator controls


Update some properties of the UserTypeComboBox:

  1. DataSource = +Other Data Source, +Project Data Source, +ComputerUsersDataSet, and finally selected UserTypes.

This created UserTypesBindingSource and UserTypesTableAdapter

  1. DisplayMember = UserTypeName
  2. ValueMember = UserTypeId
  3. SelectedValue = UsersBindingSource-UserType


When I run the application, select + (add new item), I typed some names for First & Last Name. After chosing one item in the UserTypeComboBox say Programmer, the app just sticked with UserTypeComboBox. Other fields cannot be selected, or clicking the save icon do nothing.


I have to use STOP in VS/VB IDE.


I tried to change ComboBox.DropDownStyle to Simple, DropDown, and DropDownList but still the same problem.


Any ideas Did I missed something

Larry Sevilla

A novice VB2005 user.

App Source: Visual Basic 2005 Programmer’s Reference by Rod Stephens

Chapter 11 Database Controls & Objects, Complex Data Binding, p 356.



Answer this question

Problem with “data bound ComboBox” with “Visual Basic 2005”

  • &#169&#59; Ţĩмό Şąļσмāĸ

    Hi Jared, (and everybody)

    First, thx for your reply.

    I tried what you said. But there is no line of code that it displayed where it hungs.

    Pls take note that I did NOT write any code. (novice...)

    Have you tried it yourself (its a very small app) Did it behave well

    With my installation of VB2005 Express & Pro, I cannot getout of combobox, I cannot even close the app.

    Larry Sevilla
    VB2005 Novice User


  • PhaedoHD

    I realize this is an old thread, but I was having the same problem with comboboxes as a novice developer and yanoyanocano's reference to setting the Focus:CausesValidation property to 'False' got me past the hangs.

    But I still don't understand why.

    Anyone have a short answer

    Thanks!

    charlie


  • NozFx

    Try running the programm under the debugger. Once it hangs hit the pause looking button and see what line of code the application is hung on.

  • Jiajia

    I got exactly the same problem in several of my applications. Setting the property "Validate" to "false" solved the problem but I don't know why. I have other applications where the combobox works and I can't see any differencies between the applications.
  • Tej62007

    Larry,

    Go to properties for combobox and set CausesValidation = false

    Regards,


  • ron8888

    I too have that problem in some applications, but not others. I don't see any difference either between applications. Also, changing the Validate property to false does not seem to solve the problem in my case.


  • Problem with “data bound ComboBox” with “Visual Basic 2005”