Ticket Q368250
Visible to All Users

WinForms "SelectedItem" DataBindings in LookUpEdit

created 13 years ago

Hello,
I'm replacing ComboBoxes (System.Windows.Forms.ComboBox) with LookUpEdits (DevExpress.XtraEditors.LookUpEdit). I used to have databindings like this:
this.comboBox1.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.orderBindingSource, "Customer", true));
this.comboBox1.DataSource = this.customerBindingSource;
this.comboBox1.DisplayMember = "Name";

IList<Customer> myCustomers = new List<Customer>;

this.customerBindingSource.DataSource = myCustomers;
So the column "Customer" in the orderBindingSource contains Objects of the type "Customer". The DataSource "customerBindingSource" contains a list of these objects. By using the "SelectedItem" property I was able to create such a DataBinding.
How can I archive this for your controls, e.g. LookUpEdit? Since I have no reference inside my Customer objects to myself, I'm not able to choose a column as ValueMember… I would need to choose "this"…
this.lookUpEdit1.DataBindings.Add(new System.Windows.Forms.Binding("EditValue", this.orderBindingSource, "Customer", true));
this.lueHaendler.Properties.ValueMember = "??";
Just as a side note: I'm using NHibernate as ORM mapper, which allows us to map each relation as a Object. The references between the relations are just plain C# object references…

Answers approved by DevExpress Support

created 13 years ago (modified 12 years ago)

Hello Stefan,
Thank you for your question. I suggest that you leave the ValueMember property unassigned. In this situation, it will be bound to the reference to an item.
Thanks,
Uriah

    Comments (2)

      Hi Uriah,
      Thanks for your quick response. I could solve my issue, I can bind the item itself now.
      Another problem occured to me, the position of the underlaying DataSource stays the same. I tried using GridLookUpEdit as suggested here:
      http://www.devexpress.com/Support/Center/p/Q259659.aspx
      But this didn't solved the problem. So I'm using the LookUpEdit with a slightly altered EditValueChanged event handler then the suggested one from here:
      http://www.devexpress.com/Support/Center/p/A2275.aspx
              private void lookUpEdit1_EditValueChanged(object sender, EventArgs e)
              {
                  LookUpEdit lookup = sender as LookUpEdit;
                  BindingManagerBase bm = BindingContext[lookup.Properties.DataSource];
                  bm.Position = lookup.Properties.GetListSourceIndex(lookUpEdit1.ItemIndex);
              }
      Still, I have not the full WinForms ComboBox behaviour now. When I assign my List to the DataSource, e.g.
      this.customerBindingSource.DataSource = myCustomers;
      The selected item on the control should switch to the first one because that's what the underlaying DataSource does…
      Thanks,
      Stefan

      DevExpress Support Team 13 years ago

        Hello Stefan,
        Our team is dedicated to addressing all your concerns. In order to better serve and track the multiple questions in your inquiry, we have taken the liberty of separating the issues you addressed. For quick and efficient responses to your concerns, we kindly request that future inquiries address one issue at a time. Your time and cooperation are appreciated.
        Please refer to this ticket for further correspondence on your second question: How to properly synchronize the LookUpEdit with the CurrencyManager?.
        Thanks,
        Uriah

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.