The EntitySpaces Community

Share and learn about the EntitySpaces Architecture.
Welcome to The EntitySpaces Community Sign in | Join | Help
in
Home Forums Photos

Two qay bindng hell !!!

Last post 08-15-2007, 3:10 PM by David.Parsons. 6 replies.
Sort Posts: Previous Next
  •  08-15-2007, 10:21 AM 4527

    Two qay bindng hell !!!

    why in god name does this not work. I have reach the point of madness. Two way databing to a combo. This should work, and it has worked. The SelectedItem will never display the related value. If both the SelectedValue and the SelectedItem are setup as shown, the windows form will not validate and it stuck?. If only the SelectedValue is databound then it work and update fine but the current value of the related collection is never shown in the combo.
    verision .730   and IPropertChangedNotify is enable in the code generation  
    Code:
    // 
                // manuIDComboBox
                // 
                this.manuIDComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedValue", this.itemBindingSource, "ManuID", true));
                this.manuIDComboBox.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.itemBindingSource, "ManuID", true));
                this.manuIDComboBox.DataSource = this.manuCollectionBindingSource;
                this.manuIDComboBox.DisplayMember = "Manufacturor";
                this.manuIDComboBox.FormattingEnabled = true;
                this.manuIDComboBox.Location = new System.Drawing.Point(82, 68);
                this.manuIDComboBox.Name = "manuIDComboBox";
                this.manuIDComboBox.Size = new System.Drawing.Size(155, 21);
                this.manuIDComboBox.TabIndex = 39;
                this.manuIDComboBox.ValueMember = "ManuID";

    Richard Young
  •  08-15-2007, 12:19 PM 4529 in reply to 4527

    Re: Two qay bindng hell !!!

    David's the goto guy on this one, let me ping David for backup. I think you might have to do this:

    Code:
    this.txtFirstName.DataBindings.Add(new Binding("Text", _Entity, EmployeesMetadata.PropertyNames.FirstName, true, 
        DataSourceUpdateMode.OnPropertyChanged));
    However, two way binding should work right out of the box, did you check the INotifyPropertyChanged checkbox on the master? 

     


    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-15-2007, 12:54 PM 4533 in reply to 4527

    Re: Two way bindng hell !!!

    OK, thanks, but I am talking about two-way binding with a combo with a collection datasource against a entity. Your code is a little different than I did it, but I am not having any problems with straight data-binding to textboxes, that work fine.
    Richard Young
  •  08-15-2007, 1:10 PM 4534 in reply to 4533

    Re: Two way bindng hell !!!

    How are you expecting two way binding to work in a combo? You mean you add an entry to the collection and the combo should update?
    EntitySpaces | Twitter | BLOG | Please honor our Software License
  •  08-15-2007, 2:16 PM 4538 in reply to 4534

    Re: Two way bindng hell !!!

    ok, the combo is populated with a collection, or really bound to a BindSource

    a entity is loaded and bound to BindingSource and that is bound to several textboxes

    the combo is populated with the foriegn keys for the entity, in this case the entity is a part with a ManuID(int) and the combo is populated with manus(display name,value manuid). I have done this before so thats what troubling me. When the form loads the combo reflects the manuid of the Entity, when you change the combo the entity ID is updated the the selected value.


    Richard Young
  •  08-15-2007, 2:42 PM 4539 in reply to 4538

    Re: Two way bindng hell !!!

    This is the way the binding looks for our ComboBox two way binding test against Northwind Employees ReportsTo:

    Code:
    EmployeesCollection collection = new EmployeesCollection();
    
    collection.Query.Select(
        collection.Query.EmployeeID,
        collection.Query.LastName,
        collection.Query.FirstName,
        collection.Query.ReportsTo);
    collection.Query.OrderBy(collection.Query.EmployeeID.Ascending);
    collection.Query.Load();
    
    EmployeesCollection lookupSupv = new EmployeesCollection();
    
    lookupSupv.Query.Select(
        lookupSupv.Query.EmployeeID,
        lookupSupv.Query.LastName,
        lookupSupv.Query.FirstName,
        " <[LastName] + ', ' + [FirstName] AS 'FullName'>");
    lookupSupv.Query.OrderBy(
        lookupSupv.Query.LastName.Ascending,
        lookupSupv.Query.FirstName.Ascending);
    lookupSupv.Query.Load();
    
    this.cbReportsTo.DisplayMember = "FullName";
    this.cbReportsTo.ValueMember =
      EmployeesMetadata.PropertyNames.EmployeeID;
    this.cbReportsTo.DataSource = lookupSupv;
    
    this.tbFirstName.DataBindings.Add(new Binding("Text",
      collection, EmployeesMetadata.PropertyNames.FirstName,
      true, DataSourceUpdateMode.OnPropertyChanged));
    this.tbLastName.DataBindings.Add(new Binding("Text",
      collection, EmployeesMetadata.PropertyNames.LastName,
      true, DataSourceUpdateMode.OnPropertyChanged));
    this.cbReportsTo.DataBindings.Add(new Binding("SelectedValue",
      collection, EmployeesMetadata.PropertyNames.ReportsTo,
      true, DataSourceUpdateMode.OnPropertyChanged));

    David Neal Parsons
    www.entityspaces.net
  •  08-15-2007, 3:10 PM 4540 in reply to 4539

    Re: Two way bindng hell !!!

    BTW, I think the default DropDownStyle is DropDown, which lets the user enter their own values. In the scenario you are describing, try changing it to DropDownList, which will restrict the choices to those in the bound collection.
    David Neal Parsons
    www.entityspaces.net
View as RSS news feed in XML