How to set RowFilter case-insensitive for DataView
Asked Answered
G

2

6

I have a datagrid, its datasource is a dataview. There is a textbox with which users can type in filter text. I want to make the filter to be case insensitive. say, the typed text is "Tg"

I tried this

Mydataview.RowFilter = "UPPER(COL) LIKE '%TG%'"

but this gives me an invalidoperation exception

then I changed it to

Mydataview.RowFilter = "COL LIKE '%tg%' or COL LIKE '%TG%'"

This works but it does not cover all cases. E.g. If a row is "Tg", it will be filtered out which is not desirable. What I want, when users type "Tg", it will match any data with tg, Tg, TG, tG, all the combination

thanks

Garrard answered 16/10, 2012 at 16:20 Comment(0)
S
13

RowFilter obeys dataset CaseSensitive value

So do this in your Form_Load method:

CaseSensitive is set to False by default

mydataset.CaseSensitive = false

Proof of concept:

enter image description here

Stockroom answered 16/10, 2012 at 16:25 Comment(5)
Thanks, I did not use dataset, I use a datatable, I tried set MyTable.CaseSensitive = false, does not workGarrard
Why don't you write all possible combinations: "COL LIKE '%tg%' or COL LIKE '%TG%' or COL LIKE '%Tg%' or COL LIKE '%tG%'"Stockroom
That's so long (though possible). If users type in "test", then I have 16 combinations. I try to avoid this if possible. thanksGarrard
thanks, I just tried with datatable, it works. I made a mistake when I tried previously.Garrard
Although I suppose there could be conditions where you want it, so this setting might have to be changed in those places if the dataset is reused....Aftertaste
T
-1

select the name twice with one of them being upper(name) as finder and then use that column (non visable) to filter your rows

Tuft answered 1/3, 2017 at 20:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.