结合使用datagridview数据表rowfilter的复选框测试和字符串测试 [英] Combine checkbox test and string test for a datagridview datatable rowfilter

查看:55
本文介绍了结合使用datagridview数据表rowfilter的复选框测试和字符串测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在2列上组合一个rowfilter组合。一列是一个复选框 - 仅显示已检查的行,同时还在另一列(字符串)上应用文本过滤器。我可以单独做每一个,但我似乎无法掌握正确的语法来组合2到1的过滤器。



我有什么尝试过:



我的DataGridView有两个不同的列,我在其上应用了rowfilter:

1)复选框列(称之为 S)

2)常规字符串列(称之为艺术家)

3)DataTable(称之为DT)

4 )DataGridView(称之为DGV)

并且它们受到约束

I want to combine a rowfilter combination on 2 columns. One column is a checkbox - show only rows that are checked and at the same time also apply a text filter on another column (string). I can do each one individually but I can't seem to get a handle on the proper syntax to combine the 2 into 1 filter.

What I have tried:

My DataGridView has 2 different columns on which I apply rowfilter:
1) Checkbox Column (Call it "S")
2) Regular String Column (Call it "Artist")
3) DataTable (Call it "DT")
4) DataGridView (Call it "DGV")
and they are bound

DGV.Datasource=DT

' Now I can apply each rowfilter individually to filter either columns that are checked:

dt.defaultview.rowfilter = "S"

' This will successfully show only rows in which the CheckColumn has been checked

dt.defaultview.rowfilter = String.format("{0} LIKE '{1}'", "Artist", strA)

' this successfully shows rows in which the Artist name contains variable strA
' I want to apply both conditions at once, but

dt.defaultview.rowfilter = "S" And String.format("{0} LIKE '{1}'", "Artist", strA)

不起作用,我收到一个无效的演员异常

从字符串S转换为类型'Long'无效。

ch eckbox one是一个布尔值(S)而另一个本质上是一个字符串



是否知道使这个组合一起工作的正确语法?

doesn't work, I get an invalid cast exception
Conversion from string "S" to type 'Long' is not valid.
checkbox one is a boolean ("S") and the other is essentially a string

Any know the proper syntax to get this combination to work together?

推荐答案

我认为你应该使用:

I think you should use:
dt.defaultview.rowfilter = "S=True AND " + String.format("{0} LIKE '{1}'", "Artist", strA)


这篇关于结合使用datagridview数据表rowfilter的复选框测试和字符串测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆