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…
WinForms "SelectedItem" DataBindings in LookUpEdit
Answers approved by DevExpress Support
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
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
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