Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用checkedlistbox从Datagridview中选择数据_C#_Sql - Fatal编程技术网

C# 使用checkedlistbox从Datagridview中选择数据

C# 使用checkedlistbox从Datagridview中选择数据,c#,sql,C#,Sql,我的表单中有一个datagridview,还有一个checkedlistbox。我已经编写了一些代码,以便可以使用checkedlistbox中选中的任何内容过滤datagridview。尽管如此,它一次只过滤一个,而我希望能够过滤任何被检查的数据。有办法解决这个问题吗 代码: if(checkedListBox1.CheckedItems.Count!=0) { 字符串s=“”; int x; for(x=0;x看起来您的for循环中有错误:“s”仅包含checkListBox中最后选中的项。

我的表单中有一个datagridview,还有一个checkedlistbox。我已经编写了一些代码,以便可以使用checkedlistbox中选中的任何内容过滤datagridview。尽管如此,它一次只过滤一个,而我希望能够过滤任何被检查的数据。有办法解决这个问题吗

代码:

if(checkedListBox1.CheckedItems.Count!=0)
{
字符串s=“”;
int x;

for(x=0;x看起来您的for循环中有错误:“s”仅包含checkListBox中最后选中的项。请尝试如下更改:

s += "'" + checkedListBox1.CheckedItems[x].ToString() + "',";
s += "'" + checkedListBox1.CheckedItems[x].ToString() + "',";