Hi,
I have an object named "Item" and i bind it with ultra combo. But i cannot set the SelectedItem for it like we do in .Net native combo by using SelectedItem property, so that when it fetches records from database, the selected item automatically sets.. Instead, here in case of ultra combo, i have set the value property of ultra combo with my Item.Key (which is the primary key) in coding.. Also at the time of saving, i have to set the Item object with Ultracombo.SelectedRow.ListObject... I think this is the overhead in ultra combo.. Since .Net native combo needs not to set these properties in coding...
Your help required...
Ovais.
Hi Mike,
thats the point! In the form load I load the user-groups now first and use this list to load and instantiates the profiles and also for binding to the combos data source.
How binding object properties is hard to find in the help and forum posts. It is somewhat of "hidden". This scenario looks very common to me if you work with business objects. I guess I can do this the same way for enum-type properties? This is also a very common scenario in my project. So far I have implemented view-classes or have exposed enum-value-int property just for binding.
Thank you Mike.
Best regards
Markus
Hi Markus,
My guess is that when you load the form, the Value of the combo is being set by the the data source to an object. That object might be the same as the object on the list, but the Equals method on an object returns true only if the objects are the same instance - and in this case, they are two different instances of the object.
In other words, even if the object returned from the DataBase has the same property values as the one on the list, they are not the same object and the Equals method will return false.
So when you click an item on the list, the Combo's value is set to the value on the list - it's the same object. But when you load the app, the Value of the combo is set by the data source to a new instance of the object and it's not the same one as the instance on the list. They don't match, so the combo doesn't know the Value matches an item on the list. You probably have your combo DropDownStyle set to DropDownList, which means the combo will not accept a value that doesn't exist on the list and so it shows blank.
One way to get around this would be to override the Equals method on your object so that it returns true when all of the properties of the objects are equal. If you do that, you should also override GetHashCode to make sure they return the same value.
Frankly, though, I'm not sure this is a great idea. Having an object that returns Equals for other instances can cause some weird issues when using DataBinding. If I were you, I would probably not bind the Value property of the combo and simply set the Value in code to an instance that is on the list.
I found this post how to specify the ValueMenber for binding objects. I can choose a object from the dropdown list of my UltraComboEditor (UltraCombo seems not to work for this) and the property of my business object "SumProfile" gets updated with the choosen value. My drop down object (class UserGroup) overrides the ToString() member and returns the "GroupName".
Problem: the next time I call my form the combo appears empty (objects are loaded ok from database). I have setup my combo editor as follows:
Form_load event:
BindingList<SumProfile> profiles = InitBindingList;
this.bindingSourceProfiles.DataSource = profiles;
List<UserGroup> list = LoadUserGoups();
this.ComboGrantedUserGroup.DropDownStyle = DropDownStyle.DropDownList;
this.ComboGrantedUserGroup.ValueMember = Infragistics.Win.BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER;this.ComboGrantedUserGroup.DisplayMember = "GroupName"; //string.Empty;this.ComboGrantedUserGroup.DataSource = list;
this.ComboGrantedUserGroup.DataBindings.Add( "Value", this.bindingSourceProfiles, "GrantedUserGroup" );
Any ideas why the combo editor dont't displays the "GrantedUserGroup" - property?
Best Regards
Hi Ovais,
No, you have to write one line of code to get what you want here.
But i dont want to write any code for combo binding.. Is there any alternative??
Waiting for your quick assitance Mike..
Thanks in advance.
Ovais