Sort using DictionaryOf(string, String)

Hi !

I set my SfCombo using a dictionary of strings as shown below:

comboGrupos.DataSource = New BindingSource(Grupos, Nothing)
comboGrupos.DisplayMember = "Key"

comboGrupos.ValueMember = "Value"


When I try to sort it using

comboGrupos.DropDownListView.View.SortDescriptors.Add(New Syncfusion.DataSource.SortDescriptor() With {.PropertyName = "Key", .Direction = Syncfusion.DataSource.ListSortDirection.Ascending})


I receive an error:

System.InvalidOperationException  HResult=0x80131509  Message=There is no coertion operation defined between types 'System.Collections.Generic.KeyValuePair`2[System.String,System.String]' and  'System.String'. Source=System.Core  

Is there any way to sort this combo using its "DisplayMember" value (field KEY)?
Thanks!

3 Replies

EM Elakkiya Muthukumarasamy Syncfusion Team July 26, 2021 12:26 PM UTC

Hi David, 
 
Greetings from Syncfusion. 
 
We have checked your reported query “Sort using DictionaryOf(string, String)” and we would like to let you know that we can able to Sort while using Dictionary of strings in SFComboBox dropdown items by using SortedDictionary.We have prepared the sample to sort the SFComboBox dropdown items in ascending and descending orders.  
 
Code snippet 
 
'Acending order 
Dim My_dict1 As New SortedDictionary(Of String, String)() 
 
 
'Decending order 
Dim My_dict1 As New SortedDictionary(Of String, String)(New Form1.DescendingComparer(Of String)()) 
 
 
 
Output: 
 
 
Please try it with the above solution and let us know if you need any further assistance on this. 
 
Regards, 
Elakkiya 



DA DavidBS replied to Elakkiya Muthukumarasamy July 26, 2021 03:05 PM UTC

Hi Elakkyia!


Great! I didn't know SortedDictionaries at all!

Thanks a lot; it had functioned perfectly.


Kindest regards,

David



VR Vijayalakshmi Roopkumar Syncfusion Team July 27, 2021 04:44 AM UTC

Hi David, 
  
We are glad that our solution helps to meet your requirement. 
  
Please get back us, if you need any further assistance on this. 
  
Thanks 
Vijayalakshmi VR 


Loader.
Up arrow icon