Hi hope someone can help,
I'm trying to bind an UltraCombo against data from a Generic.Dictionary collection object using the following code in the load event of a composite user control:
Dim BookingOrderItems As New System.Collections.Generic.Dictionary(Of BookingOrderEnum, String) With BookingOrderItems .Add(BookingOrderEnum.Any, "Any") .Add(BookingOrderEnum.HolidayBeforeTOIL, "TOIL before holiday").Add(BookingOrderEnum.TOILBeforeHoliday, "Holiday before TOIL") End WithWith ultracomboBookingOrder .ValueMember = "Key" .DisplayMember = "Value" .DataSource = BookingOrderItems End With
With BookingOrderItems
.Add(BookingOrderEnum.Any, "Any") .Add(BookingOrderEnum.HolidayBeforeTOIL, "TOIL before holiday").Add(BookingOrderEnum.TOILBeforeHoliday, "Holiday before TOIL")
.Add(BookingOrderEnum.HolidayBeforeTOIL, "TOIL before holiday")
End With
.ValueMember = "Key" .DisplayMember = "Value" .DataSource = BookingOrderItems
.ValueMember = "Key"
.DisplayMember = "Value"
.DataSource = BookingOrderItems
This results in a System.NullReferenceException at the point where i assign BookingOrderItems object to the data source property.
If i change the above code to use a simple Generic.List of strings as in the following code then the everything works fine.
Dim BookingOrderItems As New System.Collections.Generic.List(Of String)
.Add("Any") .Add("TOIL before holiday") .Add("Holiday before TOIL") End With
.Add("Any") .Add("TOIL before holiday") .Add("Holiday before TOIL")
.Add("TOIL before holiday")
.Add("Holiday before TOIL")
Me.ultracomboBookingOrder.DataSource = BookingOrderItems
I would therefore assume i'm missing something in how i'm going about setting up the binding.
Please excuse any obvious errors in the above code as i'm new to using the UltraCombo.
Thanks for any help,
Simon.
I tried the same and ended up here:
var list = new List<KeyValuePair<PaymentTransferType, string>>(); list.Add(new KeyValuePair<PaymentTransferType, string>( PaymentTransferType.All, "{alle}");list.Add(new KeyValuePair<PaymentTransferType, string>( PaymentTransferType.BankCollection, "Bankeinzug"));list.Add(new KeyValuePair<PaymentTransferType, string>( PaymentTransferType.Transfer, "Überweisung"));combo.DataSource = list;combo.ValueMember = "Key";combo.DisplayMember = "Value";
I think this comes nearest to your approach...
tia Ernst
-- http://www.ieg-tools.net
Hi Mike
Thanks for the prompt reply. The data source restriction would explain why the Generic.List(Of T) works and the Dictionary dosent, since the generic List implements IList.
The Dictionary only implements IEnumerable and ICollection and not the interfaces you specified. I'll probably just have to stick with the List objet and write code to convert the string values to and from the enumeration.
To give you some context; my company is looking to take advantage of consistent UI styling using .ISL styles files and so are replacing all Windows forms UI with infragistics UI for the next release of our product. Up until now we have mainly only been using the grid and so there is something of a learning curve getting up to speed with the other controls in the suite.
Hi Simon,
I don't think you can use a Dictionary as the data source for a grid. The grid's Data Source must be an IList or an IBindingList. I could be wrong, but my guess is that a Dictionary does not implement either of those interfaces. Are dictionaries enumerable?