简体   繁体   English

DataView.Rowfilter循环中的多个过滤器

[英]DataView.Rowfilter multiple filter in Loop

DataView DV = DataTable.AsDataView();
for(int i=0; i<ConditonQueue.Count; i++)
{
     DV.RowFilter = ConditonQueue.ElementAt(i);
}

Here after the loop DV is filtered only for last element in ConditionQueue . 这里,在循环之后,仅针对ConditionQueue最后一个元素过滤DV How can I get DV with all filter condition on queue applied? 如何在队列中应用所有过滤条件的情况下获得DV ConditonQueue.ElementAt(i) returns a string, which is a valid expression for RowFilter . ConditonQueue.ElementAt(i)返回一个字符串,该字符串是RowFilter的有效表达式。

Combining all ConditonQueue.ElementAt(i) will not help in my scenario. 组合所有ConditonQueue.ElementAt(i)在我的方案中无济于事。 I want to apply RowFilter each time. 我想每次都应用RowFilter

As I need to do some calculation after each RowFilter . 因为我需要在每个RowFilter之后进行一些计算。 AND ing all conditions will not help. AND所有条件都无济于事。

Is there any other way to recreate the DV when RowFilter is applied in loop each time? 每次在循环中应用RowFilter时,还有其他方法可以重新创建DV吗?

Lots of assumption as your question is not clear. 由于您的问题不清楚,因此有很多假设。 Try this 尝试这个

DataView DV = DataTable.AsDataView();

string[] filter = new string[ConditonQueue.Count];
for(int i=0; i<ConditonQueue.Count; i++)
{
     filter[i] =  ConditonQueue.ElementAt(i).ToString();
}

DV.RowFilter = String.Join(" AND ", filter); // filter1 AND filter2 AND ... AND filterN

I don't like your approach, am sorry to say but I think you have to update the DV so that the new filter is applied to already filtered view 我不喜欢您的方法,很遗憾地说,但是我认为您必须更新DV,以便将新过滤器应用于已过滤的视图

for(int i=0; i<ConditonQueue.Count; i++)
{
     DV.RowFilter = ConditonQueue.ElementAt(i);
     DV = DV.ToTable().AsDataView();
}

The RowFilter ist automatically applied to all rows in the data view. RowFilter ist自动应用于数据视图中的所有行。 The correct usage would be to combine all conditions of the queue into an appropriate string expression and pass that expression to the RowFilter property. 正确的用法是将队列的所有条件组合成适当的字符串表达式,然后将该表达式传递给RowFilter属性。

Also have a look at http://www.csharp-examples.net/dataview-rowfilter/ for examples of the RowFilter syntax. 还可以查看http://www.csharp-examples.net/dataview-rowfilter/以获取RowFilter语法的示例。

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

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