noccy Posted December 15, 2006 Posted December 15, 2006 Hi! I am trying to highlight the search query in a gridview like this: 'foo is the gridview 'strQuery is the search string Dim itm As Object Dim cel As TableCell Dim iHit As Integer Dim strOriginal As String Dim strStart As String If Len(strQuery) > 0 Then For Each itm In foo.Rows For Each cel In itm.Cells If cel.Text.ToLower.Contains(strQuery.ToLower) And cel.Text <> " " Then strStart = "" strOriginal = cel.Text iHit = InStr(strOriginal.ToLower, strQuery.ToLower) If iHit > 1 Then strStart = Left(strOriginal, iHit - 1) End If cel.Text = strStart & "<span style=color:red;background-color:Lime;font-weight:bold>" & Mid(strOriginal, iHit, Len(strQuery)) & "</span>" cel.Text = cel.Text & Right(strOriginal, Len(strOriginal) - (iHit + Len(strQuery)) + 1) End If Next Next End If This works like charm, but if the search string contains any special charachters like the norwegian æ, ø and å, it wont work.... Any ideas? noccy Quote
alreadyused Posted December 15, 2006 Posted December 15, 2006 special char to lower What do the special chars equal when converted to lower? Meaning, what is the toupper and the tolower of the æ, ø and å? Just a guess but since it works w/o those characters, that's probably where the error's at, and it never finds it's tolower version in the table, so you're going to have to find a way to handle those. I haven't messed with this so there's probably a better way, but I'm pretty sure this would work: Look at each char in the querystring: if it's a standard, convert.tolower then append to a stringbuilder if it's not standard, just append to the stringbuilder. When you've finished converting the query into the stringbuilder, then use the stringbuilder.tostring to compare to your cells. Quote
Administrators PlausiblyDamp Posted December 15, 2006 Administrators Posted December 15, 2006 If you are using .Net then try the string methods for comparisons etc. rather than the VB style ones. The .Net 2 methods allow you to specify the compare options you need i.e. ihit = strOriginal.IndexOf(strQuery, StringComparison.CurrentCultureIgnoreCase) this will prevent errors where upper and lower case cannot simply be converted and should be more reliable. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
noccy Posted December 15, 2006 Author Posted December 15, 2006 Yes, it seems to be a problem with upper and lower... "Å" ToLower returns "Å"... I will try your suggestions as soon as I am back at work... Thanks :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.