Hi,
I'm trying to bind to the selected item in an UltraCombo. After reading some posts that encouraged me to set the ValueMember = Infragistics.Win.BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER, I thought i was getting closer.
Now I find myself in the situation where I've tried the following
Declare the Selected Object
private DataObject _selectedComboDataObject; public DataObject SelectedComboDataObject { get { return _selectedComboDataObject; } set { _selectedComboDataObject = value; NotifyPropertyChanged(); } }
and set up the UltraCombo's data bindings to its data source, and an attempt at binding to the SelectedComboDataObject.
(this is done in the constructor after the InitializeComponent Method is called)
ultraCombo1.DisplayMember = "Prop2";ultraCombo1.SetDataBinding(DataObjects, null);ultraCombo1.ValueMember = Infragistics.Win.BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER;Binding c = new Binding("Value", this, "SelectedComboDataObject", false, DataSourceUpdateMode.OnPropertyChanged);ultraCombo1.DataBindings.Add(c);
I've included my sample w/ the "DataObject" class and the population of the "DataObjects" binding list.
thank you very much.
Hi Priehl,
USE_LISTOBJECT_AS_VALUEMEMBER is only supported for UltraComboEditor. It is not supported for UltraCombo. You can handle this using an unbound colmun that contains the ListObject.
We modified your sample to demonstrate how you can accomplish this. Please take a look and let me know whether it works for you.
Hi Mike,
thank you for the response. I totally understand what you're doing, and am very much willing to take a similar approach. The only problem I have is that the setter for SelectedComboDataObject is never called. I've downloaded your code with and made no changes.
I'm also having problems with the other simple bindings on the form. Nothing seems to be working. Could there be something simple that i turned off?
thank you.
Assuming the UltraCombo is on the form and the method is only called once for each UltraCombo, we see no potential issues. It may be a good idea to put something in place to prevent the method from being called multiple times for the same combo, such as using a flag or a collection to track which combos have an event associated.
Wow, I will be turning that on for the duration. Thanks for clearing that up for me.
I went ahead and created an extension method to go through the steps mentioned above.
Could someone comment on when this might need to be called in the lifecycle of the UltraCombo, and any clean up that i may need to do when the object is disposed. If someone could offer those suggestions, i'd be happy to close this thread.
public static void BindUltraCombo(this UltraCombo uc, string propertyNameToBind, object bindingDataSource, string displayMember, object dataSource){ const string objectColumnName = "Object"; uc.ValueMember = objectColumnName; Binding c = new Binding("Value", bindingDataSource, propertyNameToBind, false, DataSourceUpdateMode.OnPropertyChanged); uc.DataBindings.Add(c); uc.InitializeLayout += (sender, e) => { var band = e.Layout.Bands[0]; if (!band.Columns.Exists(objectColumnName)) { var newColumn = band.Columns.Add(objectColumnName); newColumn.DataType = typeof(DataObject); newColumn.Hidden = true; } }; uc.InitializeRow += (sender, e) => { if (e.Row.Cells.Exists(objectColumnName)) { e.Row.Cells[objectColumnName].Value = e.Row.ListObject; } }; uc.DisplayMember = displayMember; uc.SetDataBinding(dataSource, null);}
In the attached sample, I'm calling it like this, and this is my only mention of the ultraCombo1 control.
ultraCombo1.BindUltraCombo("SelectedComboDataObject", this, "Prop2", DataObjects);
I took a look at the sample and I get the same results, but I don't think this has anything to do with the combo. If you set the IDE to break on all exceptions, you will see that there is an ArgumentException being raised when the application runs. This is caused by the bindings you are adding to ultraLabel4.
I'm not absolutely sure, but my guess is that this is caused by the fact that you are trying to bind to a property on the SelectedComboDataObject. My guess is that the BindingManager is trying to populate label4, but since SelectedComboDataObject is null, it cannot access Prop1 and once it hits an exception, it's giving up on all bindings.
If I comment out that line of code, it works fine.
//ultraLabel4.DataBindings.Add("Text", this, "SelectedComboDataObject.Prop1");