G
Guest
I have asked several question over the last week and have not gotten any
answers! What's up with that? Here is one I asked over a week ago:
____________________________________________________________
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?
___________________________________________________________________
In a subsequent post, I pointed out that the data was sorted correctly by
SQL server but not by the .NET framework.
I have since discovered that:
1) The data on SQL is varchar, not nvarchar. If it was nvarchar, then it
sorts just like the framework.
2) In oder for this thing to come close to working I needed to change my
search routine to use the following compare:
result = String.Compare(rowval, searchval, True, CC)
where CC = Globalization.CultureInfo.CurrentCulture
but this still leaves some problems with the search.
3)I found the following under help for CompareOption Enumeration:
The .NET Framework uses three distinct ways of sorting: word sort, string
sort, and ordinal sort. Word sort performs a culture-sensitive comparison of
strings. Certain nonalphanumeric characters might have special weights
assigned to them; for example, the hyphen ("-") might have a very small
weight assigned to it so that "coop" and "co-op" appear next to each other in
a sorted list. String sort is similar to word sort, except that there are no
special cases; therefore, all nonalphanumeric symbols come before all
alphanumeric characters. Ordinal sort compares strings based on the Unicode
values of each element of the string.
_________________________________________________________________
Great, so all I have to do is tell the framework I want the 'string sort'
sort! But you can't tell the CompareInfo class what the default sort type
should be! And you can't tell the dataview class to use a different comparer!
This seems to me to be a bug, or at least an oversight.
So if I want it sorted the 'sort string' way, what am I suppose to do? The
only thing I can think of, is to create an arraylist, with the data
(companyname) and an index to the original table, a routine to call the
CompareInfo.compare routine with the compare options I want and then use the
arraylist.sort(mycomparer) an then load the new table based on the sorted
array. Anyone got a better idea? Besides removing the '-' from the data,
which maybe just what I do!
TIA,
answers! What's up with that? Here is one I asked over a week ago:
____________________________________________________________
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?
___________________________________________________________________
In a subsequent post, I pointed out that the data was sorted correctly by
SQL server but not by the .NET framework.
I have since discovered that:
1) The data on SQL is varchar, not nvarchar. If it was nvarchar, then it
sorts just like the framework.
2) In oder for this thing to come close to working I needed to change my
search routine to use the following compare:
result = String.Compare(rowval, searchval, True, CC)
where CC = Globalization.CultureInfo.CurrentCulture
but this still leaves some problems with the search.
3)I found the following under help for CompareOption Enumeration:
The .NET Framework uses three distinct ways of sorting: word sort, string
sort, and ordinal sort. Word sort performs a culture-sensitive comparison of
strings. Certain nonalphanumeric characters might have special weights
assigned to them; for example, the hyphen ("-") might have a very small
weight assigned to it so that "coop" and "co-op" appear next to each other in
a sorted list. String sort is similar to word sort, except that there are no
special cases; therefore, all nonalphanumeric symbols come before all
alphanumeric characters. Ordinal sort compares strings based on the Unicode
values of each element of the string.
_________________________________________________________________
Great, so all I have to do is tell the framework I want the 'string sort'
sort! But you can't tell the CompareInfo class what the default sort type
should be! And you can't tell the dataview class to use a different comparer!
This seems to me to be a bug, or at least an oversight.
So if I want it sorted the 'sort string' way, what am I suppose to do? The
only thing I can think of, is to create an arraylist, with the data
(companyname) and an index to the original table, a routine to call the
CompareInfo.compare routine with the compare options I want and then use the
arraylist.sort(mycomparer) an then load the new table based on the sorted
array. Anyone got a better idea? Besides removing the '-' from the data,
which maybe just what I do!
TIA,