如何为 DefaultView Rowfilter 添加新的
How to DefultView Rowfilter add new
private void categoryCheckedListBox_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{
if (e.State==CheckState.Checked)
{
string categoryName = categoryCheckedListBox.Items[e.Index].Value.ToString();
(productListGV.DataSource as DataTable).DefaultView.RowFilter = string.Format("Kata2 LIKE '%{0}%' AND Kata1 LIKE '%{1}%'", categoryName,Cins);
}
else
{
(productListGV.DataSource as DataTable).DefaultView.RowFilter = null;
}
}
你好类别听起来总是不同的和动态的。我想要的是将它添加到每个选定复选框值的过滤器中。 CategoryName 可以有不同的值。
我做了DefaultView.RowFilter+=....但是是错误的。
迭代 categoryCheckedListBox.Items
,根据迭代组成你的 string.Format
String
,然后传递给 string.Format
s Object
一个数组,其中包含选中的相应的字符串。
示例:
using System;
using System.Linq;
// Lacking actual data, I made an assumption that Kata concatenated with the key will correspond to the actual column
(productListGV.DataSource as DataTable).DefaultView.RowFilter = string.Join(" AND ", new[] { "a", "b", "c" }.Select((val, key) => $"Kata{key} LIKE '%{val}%'" ));
或者:
using System;
string[] a = new[] { "a", "b", "c" };
string s = String.Empty;
for (int i = 0; i < a.Length; i++) s+= $"Kata{i} LIKE '%{a[i]}%'";
(productListGV.DataSource as DataTable).DefaultView.RowFilter = string.Format(s, a);
我相信你明白了。
private void categoryCheckedListBox_ItemCheck(object sender, DevExpress.XtraEditors.Controls.ItemCheckEventArgs e)
{
if (e.State==CheckState.Checked)
{
string categoryName = categoryCheckedListBox.Items[e.Index].Value.ToString();
(productListGV.DataSource as DataTable).DefaultView.RowFilter = string.Format("Kata2 LIKE '%{0}%' AND Kata1 LIKE '%{1}%'", categoryName,Cins);
}
else
{
(productListGV.DataSource as DataTable).DefaultView.RowFilter = null;
}
}
你好类别听起来总是不同的和动态的。我想要的是将它添加到每个选定复选框值的过滤器中。 CategoryName 可以有不同的值。
我做了DefaultView.RowFilter+=....但是是错误的。
迭代 categoryCheckedListBox.Items
,根据迭代组成你的 string.Format
String
,然后传递给 string.Format
s Object
一个数组,其中包含选中的相应的字符串。
示例:
using System;
using System.Linq;
// Lacking actual data, I made an assumption that Kata concatenated with the key will correspond to the actual column
(productListGV.DataSource as DataTable).DefaultView.RowFilter = string.Join(" AND ", new[] { "a", "b", "c" }.Select((val, key) => $"Kata{key} LIKE '%{val}%'" ));
或者:
using System;
string[] a = new[] { "a", "b", "c" };
string s = String.Empty;
for (int i = 0; i < a.Length; i++) s+= $"Kata{i} LIKE '%{a[i]}%'";
(productListGV.DataSource as DataTable).DefaultView.RowFilter = string.Format(s, a);
我相信你明白了。