views:

280

answers:

3

Given my table primary table for the binding navigator:

CREATE TABLE [dbo].[asset](
[assetID] [int] IDENTITY(1,1) primary key,
[assetTag] [varchar](15) NULL,
[assetModelId] [int] NOT NULL,
[employeeId] [int] NULL references employee(employeeid),
[LocationId] [int] NULL,
[purchasedDate] [smalldatetime] NULL,
[purchasedby] [int] NULL references employee(employeeid),
[depreciated] [tinyint] NULL,
[addedDate] [smalldatetime] NULL CONSTRAINT,
[addedBy] [int] NULL references employee(employeeid),
[disposalDate] [smalldatetime] NULL

Here's the bindingNavigator binding:

bindingNavigator1.BindingSource = _formData.BsAssets; // binding source for the asset table(linq-to-sql dbml)

Here's the binding code for the comboBox:

        _BsAsset.DataSource = _formData.GPS.dc.assets;
        _BsUser.DataSource = _formData.GPS.dc.employees;
        cmbUser.DisplayMember = "userName";
        cmbUser.ValueMember = "employeeId";
        cmbUser.DataSource = _BsUser;

        cmbUser.DataBindings.Add("SelectedValue", _BsAsset, "employeeId");

Each time I select a value on the combo box it stays... until the control loses focus, then it sets it back to a blank(null).

The combo box is set to DropDown mode so that users can add new values on that table directly from this comboBox. If I type in a value that value stays( I haven't put any code in to implement this functionality yet).

I am using the same code to bind combo boxes to the other two values that reference the employee table, with the same result. Why does it keep setting it back to null after I select something?

A: 

Sounds like the dropdown control is being reloaded every time when its looses focus. Is the page posted back when it looses focus of the control?

Chuckie
sorry, perhaps I should have mentioned it's windows forms, not asp
Maslow
A: 

The DisplayMember property is set to userName which does not exist in your datasource.

devnull
my dataSource is the employees table which does have a userName property. Also I can see the list of unsernames in the combox box, even when I comment out the DataBindings.Add line.
Maslow
A: 

I found an interesting thing. When I went to properties for the combo box, then to DataBindings/Advanced, and removed the Text entry, suddenly the combo box stopped blanking out when it lost focus. Might be worth a try.

Tommy Christopherson