How do I get the Index of an UltraComboEditor ValueList Item?

Viewed 221

I have an UltraComboEditor named ddltype

I set the values with an Enumeration:

ddlType.Items.Add(SalesPaymentType.CashPayment.Value, SalesPaymentType.CashPayment.DisplayName)
ddlType.Items.Add(SalesPaymentType.CheckPayment.Value, SalesPaymentType.CheckPayment.DisplayName)
ddlType.Items.Add(SalesPaymentType.CreditCardPayment.Value,  SalesPaymentType.CreditCardPayment.DisplayName)

When I try to set the SelectedIndex with

ddlType.SelectedIndex = ddlType.Items.ValueList.FindString(SalesPaymentType.CashPayment.DisplayName)

It returns 0 not found. It is not finding my entry.

1 Answers

Any enumerated values can be added to the UltraComboEditor control as below:

ultraComboEditor1.Items.Add(new ValueListItem(value, value.ToString))

One of the ValueListItem() constructors gets data value and display text.

To find item by string:

ultraComboEditor1.SelectedIndex = ultraComboEditor1.FindString(SalesPaymentType.CashPayment.ToString)

But more reasonable to use the FindByDataValue():

ultraComboEditor1.SelectedItem = ultraComboEditor1.ValueList.FindByDataValue(SalesPaymentType.CashPayment)

Pay attention, the FindByDataValue() requires a value, but not a text.

Related