简体   繁体   English

Datagridview数值过滤器-.net

[英]Datagridview Numeric Filter - .net

I'm attempting to filter a datagrid based on a column called "Op No#". 我正在尝试基于称为“ Op No#”的列来过滤数据网格。 When someone puts a value into the textbox I build up a string containing the filter and then apply that to the datagrid (I've omitted that part as it works with other, text, fields I've tried it on). 当有人在文本框中输入一个值时,我建立了一个包含过滤器的字符串,然后将其应用于数据网格(我已经忽略了该部分,因为它与我尝试过的其他文本字段一起使用)。

The problem I'm encountering is that when I put a number into the textbox and apply the filter it doesn't return any results and I can't see any reason for this. 我遇到的问题是,当我在文本框中输入数字并应用过滤器时,它不会返回任何结果,并且我也看不到任何原因。 Any help would be greatly appreciated. 任何帮助将不胜感激。

    If MainView.TextBox2.Text <> "" Then
        If MainView.FilterCount = 0 Then
            MainView.FilterStr = "'*[Op No#]*' like '%" & MainView.TextBox2.Text & "%'" : MainView.FilterCount = MainView.FilterCount + 1
        Else
            MainView.FilterStr = MainView.FilterStr & "and" & "'*[Op No#]*' like '%" & Convert.ToInt32(MainView.TextBox2.Text) & "%'" : MainView.FilterCount = MainView.FilterCount + 1
        End If
    End If

Your main filter string is wrong from what I can see... change this 从我所看到的,您的主过滤器字符串是错误的...对此进行更改

"'*[Op No#]*' like '%" & MainView.TextBox2.Text & "%'" 

To this...for numbers only... 为此...仅适用于数字...

 "Column name = " & MainView.TextBox2.Text

Another Example... 另一个例子...

 DataView.RowFilter = "Year = 2008"

Your filter syntax is wrong and you're doing a like on an integer...your wrapping it in ticks and percent symbols...dont do this. 您的过滤器语法是错误的,并且您正在对整数执行类似操作……您将其包装在刻度和百分号中……不要这样做。

Also theres a pound symbol after your column and thats fine, just make sure its wrapped in brackets like you have, i didnt show this. 在您的专栏后面也有一个磅符号,这很好,只需确保像您一样将其包裹在方括号中,我没有显示出来。

String values are enclosed within single quotes ' '. 字符串值用单引号''引起来。 If the string contains single quote ', the quote must be doubled. 如果字符串包含单引号',则引号必须加倍。 Number values are not enclosed within any characters. 数字值不包含在任何字符中。 The values should be the same as is the result of int.ToString() or float.ToString() method for invariant or English culture. 该值应与不变或英语区域性的int.ToString()或float.ToString()方法的结果相同。

Heres more information... http://www.csharp-examples.net/dataview-rowfilter/ 这是更多信息... http://www.csharp-examples.net/dataview-rowfilter/

Hope this helps... 希望这可以帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM