We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Sorting and Autocomplete control

Hello,

I am using autocomplete and a text box control to show a list of integers. The dataset coming off the database shows them correctly sorted, but when displayed in the text box control they are sorted as if they were text. Is there a way to change this to show them sorted as integers?

Thanks,

Scott Griswold

1 Reply

AJ Ajish Syncfusion Team August 9, 2007 09:54 PM UTC

Hi Scott,

The default behavior of autocomplete is to do a sort as text, to make a numeric sort and then list the sorted data on the autocomplete you can do that by using IComparer interface. To sort the string in Numeric fashion use the following code

string[] str = NumericComparer ns = new NumericComparer();
Array.Sort(files, ns);

and set the sorted Array as the datasource for Autocomplete. Here is the sample for your reference

Sample: http://websamples.syncfusion.com/samples/Tools.Windows/F67170/main.htm

The class StringLogicalComparer in my C# code emulates StrCmpLogicalW, and NumericComparer is a class implementing the System.Collections.IComparer interface to be used to sort collections. The natural numeric order comparer for strings is defined in a class named NumericComparer : IComparer and can be found in the sample code.

Note : Make sure that you make AutoSortList property of Autocomplete to false before you apply this custom numeric sorted data as datasource.

Kindly take a look and let me know if this helps.

Thanks,
Ajish.

Loader.
Live Chat Icon For mobile
Up arrow icon