如何使用用户控制弹出窗口过滤datagridview [英] how to filter datagridview with user control popup

查看:169
本文介绍了如何使用用户控制弹出窗口过滤datagridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户控件弹出在datagridview单元格上双击并填写 strings.Add(dataGridView1.Rows [i] .Cells [e.ColumnIndex] .Value.ToString()); 在用户控件中是checkedlistbox和一个按钮。如何使用bindingSource.filter = string.Format(LoadName LIKE{}),在按钮上过滤datagridview并检查ListBox1.CheckedItems;
谢谢

解决方案

我想,你需要这样的东西:

  var checkedValues = strings.Where(s => IsChecked(s))
.Select(s =>'+ s +%')
.ToArray();
bindingSource.Filter =LoadName LIKE+ string.Join(or,checkedValues);

其中 IsChecked()是一种假冒法您应该将其替换为告知您的值是否在您的 CheckedListBox 中。



假设您的 CheckedListBox 项是字符串,您可以替换行:

strings.Where(s => IsChecked(s))

与此一个:

ceckedListBox.CheckedItems.Cast< string>() p>

my user control popup on datagridview cell double click and fills strings.Add(dataGridView1.Rows[i].Cells[e.ColumnIndex].Value.ToString()); in user control is checkedlistbox and one button. how can i filter datagridview on button click and checkedListBox1.CheckedItems using bindingSource.filter = string.Format("LoadName LIKE '{}'", ); Thanks

解决方案

I think, you need something like this:

var checkedValues = strings.Where(s => IsChecked(s))
                           .Select(s => "'"+s+"%'")
                           .ToArray();
bindingSource.Filter = "LoadName LIKE " + string.Join(" or ",checkedValues);

Where IsChecked() is a fake method, you should replace it with something telling you if the value is checked or not in your CheckedListBox.

Supposing your CheckedListBox items are strings, you can replace the line:
strings.Where(s => IsChecked(s))
with this one:
ceckedListBox.CheckedItems.Cast<string>()

这篇关于如何使用用户控制弹出窗口过滤datagridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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