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

LarrySevilla

New member
Joined
Oct 15, 2006
Messages
4
Programming Experience
Beginner
(I'm not sure if this is the right forum)

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

2. DisplayMember = UserTypeName
3. ValueMember = UserTypeId
4. 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
VB2005 Novice user

App Source:
Visual Basic 2005 Programmer’s Reference by Rod Stephens
Chapter 11 Database Controls & Objects,
Complex Data Binding, p 356.
 
You probably forgot to remove the binding from the .Text property..


It is, additionally, not necessary to create the relation you describe here:
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_UserType

I am currently assessing whether the BindingSource is needed for the combo's lookup table. I suspect it is not.
 
I have so far failed to replicate the lockup, but I recall this issue has occurred before, and quite recently. I and JMcIlhinney helped a guy with the same issue as you, but I cannot recall anything significant enough about the thread to make a search possible :(
 
Dear Cjard,

"You probably forgot to remove the binding from the .Text property."

Thanks... Unbinding .Text property solved the problem...
It was automatically bound when I dragged from Data Sources into the form.

Larry
 
;)

When doing these kind of lookup combos i do this:
Drag the combo to the form
Open properties
Expand the (Data BIndings) property grouping
Cut the contents out of TEXT and pasted them into SELECTEDVALUE
Reset the DataSource to nothing (in the proerpties grid bit) then bind the lookup table in code.

This way, i dont get caught out by the .Text trap because I physically move the binding in the designer, from text into selected value :)
 
Back
Top