Sorting and Searching Question - and the '-' character.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am implementing an 'incremental search', where as the user types into a
textbox, a datagridview's current position is updated to match the first
record that contains what the user has typed so far. In this particular
case, I am searching the 'CompanyName' column of the underlying dataview,
which of course is sorted by this column. I have noticed that company names
like "U-Freight" and "U-Haul" appear after company names like "UBS" and "UC
Surgeons" instead of before a company name like "U.S. Steel". But when I am
searching and compare "U-" to "U.S. Steel", it says that the later is the
greater! It appears the '-' is ignored when the sort is done. Is there a
way to change this behavior?
TIA,
 
If I have SQL server sort the company names, it returns them in the correct
order. That is, U-HAUL comes before U.S. Steel. So it has to be something
in VB or the framework.
 
If I have SQL server sort the company names, it returns them in the
correct order. That is, U-HAUL comes before U.S. Steel. So it has to
be something in VB or the framework.

You probably have the collation sequence set up differently. SQL Server
allows you to set a collation sequence (order in which text is
stored/sorted).

To do something similar in VB.NET... you probably have to implement a
custom comparer? Otherwise I'll use the default language collation which
explains why . comes before -?
 
My guess is it has something to do with 'culture'. But it seems to me that
the default behavior for sorting a dataview should be the same as how SQL
server would sort it. Does someone know exactly what needs to be done? I
have gotten around the problem by loading the table sorted and then using the
default view.
 
Yes, but the collation it is using should be the same as the one that the
string.compare function uses, by default - should it not? And the '-' is
treated like it does not exist in the sort. For example:
AB
A-C
AD
AE
A-F
etc.
So, how do I tell it to stop ignoring the '-'?
 
Back
Top