views:

452

answers:

0

My combobox reverts to unselected, some time later thanks to the currencyManager. The databinding for the SelectedValue does not fire its parse event, the setter for the current object's bound property never fires. There are several other properties bound to the same bindingSource for their value that work.

The comboBox below it, which is a different fkey table, works fine, setter is called immediately. Also I put a break point in .net's BindToObject.cs which stopped when this comboBox was changed, but not the one that is having issues. The good comboBox hits the break points on BindToType and SetValue.

This comboBox's selected value is being bound to a nullable int. Which I understand has problems. so I tried this link's idea of hooking to the databinding's parse event. Which isn't firing. I tried changing the .dbml to pretend the value wasn't nullable just to see if that was the cause, and nothing changed.

Here's my comboBox designer code:

  // 
  // _cmbApplication
  // 
  this._cmbApplication.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend;
  this._cmbApplication.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.ListItems;
  this._cmbApplication.DataSource = this.bsZApplication;
  this._cmbApplication.DisplayMember = "appName";
  this._cmbApplication.Dock = System.Windows.Forms.DockStyle.Fill;
  this._cmbApplication.FormattingEnabled = true;
  this._cmbApplication.Location = new System.Drawing.Point(93, 3);
  this._cmbApplication.Margin = new System.Windows.Forms.Padding(3, 3, 25, 3);
  this._cmbApplication.MaximumSize = new System.Drawing.Size(200, 0);
  this._cmbApplication.MinimumSize = new System.Drawing.Size(85, 0);
  this._cmbApplication.Name = "_cmbApplication";
  this._cmbApplication.Size = new System.Drawing.Size(200, 21);
  this._cmbApplication.TabIndex = 2;
  this._cmbApplication.ValueMember = "applicationId";
  this._cmbApplication.Validating += new System.ComponentModel.CancelEventHandler(this.cmbApplication_Validating);
  this._cmbApplication.Validated += new System.EventHandler(this.cmbApplication_Validated);

Here's the relevant parts of my form initialization code:

        _ticketCache = _dataLayer.GetMyTickets();
  _bsTicket.DataSource = _ticketCache;
  Debug.WriteLine("application has " + _cmbApplication.DataBindings.Count + " databindings");
  var appBinding = new Binding("SelectedValue", _bsTicket, "ApplicationId", true,DataSourceUpdateMode.OnPropertyChanged);
  appBinding.Parse += (sender, e) => ModifyCurrentIfNotNull(ticket => ticket.ApplicationId =(int) e.Value);
  _cmbApplication.DataBindings.Add(appBinding);
  Debug.WriteLine("application has " + _cmbApplication.DataBindings.Count + " databindings");
  Debugger.Break();