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.
If you want the UltraCombo's value to be associated with the actual ListObject of the row, rather than a particular field in that row, you can do this:
this.ultraCombo1.ValueMember = Infragistics.Win.BindableValueList.USE_LISTOBJECT_AS_VALUEMEMBER
Thanks Mike.
But i dont want to write any code for combo binding.. Is there any alternate?
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,
Yeah, I can understand how DataBinding might be confusing and arcane in some ways.
I'm not sure I understand exactly what you mean about enum-type properties. An Enum would not have the same problem because enums are value types and therefore the Equals operator on an enum will return true for the same value regardless of the instance. It's only object types that do an instance comparison.
Using an object as a data value is kind've unusual, in my experience. Most people use a primary key value, which is usually numeric.
In my scenarios it is very common to have a objects not only exposing properties of basic types. Fully understanding how to bind object and enum properties prevents me often implementing view classes. For persistent objects I have an ID (numeric) and it would be possible to bind that way you mentioned. For other objects I can not. I just like to understand the scenarios to choose the best:
public class SumProfile {
// Enum Property
public CalcModes { get { return mode;} set { mode= value} }
// Object property
public UserGroup { get { return group;} set { group= value} }
}
We have discussed the object property so far and I know how it works now. My question was if the enum property works the same way. If I bind the enum property I always get a string value and not the enum (int) value. Therefore the value does not get updated in my object. For these properties I exposes a enumValue property sometimes but I don't like to have such properties in my business objects. What is the best way to bind (standalone combo) enum values?
I hope you understand my question (sorry, its not my home language).
No... enums do not work the same way as objects. Enums are essentially integers. So 15 = 15 and there's no such thing as having a different instance of the number 15 so there's no ambiguity in the Equals operator.
If you are getting string, then something in your code is converting to, or looking, the ToString of the enum instead of the actual e-mail value.
I know that enums are value types. I just did not found a sample so far what is the best approach to bind enum value properties. In most cases I have to localize the enums that users can choose user friendly text in the current UI culture. For this I create small DataTable with two columns (enumIntValue, localized enum text). My object has a property of enum type. For binding I need extra proeprty in my object exposing a EnumIntValue-property. In the set member of this property I convert the 'value' to the enum-value assigned to objects data field.
Do you know a better approach? Without enumIntValue-property?
Best Regards
Well... if you have a Datatable with the Enum Values and the Display Text you want, what you would do is set up the combo using the ValueMember and DisplayMember. The ValueMember is the column in the list that contains the actual enum value. The DisplayMember is what you want the user to see - the friendly localized) text. The Combo will take care of showing the DisplayMember and the Value property of the combo will return the matching Enum value. You would bind the Value property of the combo to whatever field that you want to select an enum value into.
I'm not sure why you need an enumIntValue - unless maybe your back end data source doesn't support enums. But I would think the enum would get stored as an Int, anyway. That part is a little outside my area of expertise, as it's really nothing to do with the grid. But I imagine the DotNet framework would handle converting the enum into an Int and vice versa when it gets and sets the data on the DataTable.