Building a dataview.rowfilter

  • Thread starter Thread starter Sheila Bailey
  • Start date Start date
S

Sheila Bailey

How do I build a dataview.rowfilter that will return a row for each
data field1 and the max in data field2? I tried the following, but it
did not work(always returned one row - din 3 uniqueidentifier):

dv.rowfilter = "field1 like '%' and max(field2)"

ex:
datatable:
field1 field2 field3
brk 1 uniqueidentifier
lun 1 uniqueidentifier
din 1 uniqueidentifier
brk 2 uniqueidentifier
din 2 uniqueidentifier
din 3 uniqueidentifier
sup 1 uniqueidentifier

dataview:
field1 field2 field3
brk 2 uniqueidentifier
lun 1 uniqueidentifier
din 3 uniqueidentifier
sup 1 uni1ueidentifier
 
Hi Sheila,

If I understand properly, you can't do that.
You are talking about grouping the rows.
You could create a similar table (table.Clone perhaps) and populate it with
(manually) grouped data.
Or you could group data at sql select level.

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

You can add a column, set its expression
 
What you want to do would require a group by in standard SQL.

select field1, max(field2) from datatable group by field1


this is from the expression property on MSDN which is the same operation
allowed within a rowfilter


"Note If you use a single table to create an aggregate, there would be no
group-by functionality. Instead, all rows would display the same value in
the column."
So you can do max(field2) but will not return distinct values for field1.



So you need to create a seperate table with the Distinct values of field1
(there is a selectdistinct free class out there on the web, search for
"selectdistinct") and then setup a datarelationship and create a column with
the an expression

NewDistinctDataTableColumn.Expression = MAX(Child(Childrelation).Field2)
 
Back
Top