سؤال

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. How can I get DV with all filter condition on queue applied? ConditonQueue.ElementAt(i) returns a string, which is a valid expression for RowFilter.

Combining all ConditonQueue.ElementAt(i) will not help in my scenario. I want to apply RowFilter each time.

As I need to do some calculation after each RowFilter. ANDing all conditions will not help.

Is there any other way to recreate the DV when RowFilter is applied in loop each time?

هل كانت مفيدة؟

المحلول

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

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. 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.

Also have a look at http://www.csharp-examples.net/dataview-rowfilter/ for examples of the RowFilter syntax.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top