I have two DataView
that I am trying to sort, in dgtest1 I am trying to for the exception of the data that contains a Typeid != 25
and in dgtest2 I am trying to only show the data where Typeid == 25
.
When I step through the code I am throwing an error on saying
"Cannot interpret token '!' at position 6".
Can someone show me how to properly use the string row filter?
The parameters are (Data Table table, string RowFilter, string Sort, DataViewRowState)
dgtest1.ItemsSource = new DataView(dttest1, "Typeid!= 25", "", DataViewRowState.CurrentRows);
dgtest2.ItemsSource = new DataView(dttest1, "Typeid == 25", "", DataViewRowState.CurrentRows);
The correct syntax to use for the RowFilter expression in the first Dataview constructor is
dgtest1.ItemsSource = new DataView(dttest1, "Typeid <> 25", "", DataViewRowState.CurrentRows);
^^
in the second one you need to use
dgtest2.ItemsSource = new DataView(dttest1, "Typeid = 25", "", DataViewRowState.CurrentRows);
The syntax used for the RowFilter parameter in the DataView constructor is the same used for the property Expression of the DataColumn and it is not like the equality operator of C#
EDIT Following your comment below. If Typeid is a database field of text datatype then you need to enclose the value used in the RowFilter between single quotes
dgtest1.ItemsSource = new DataView(dttest1, "Typeid <> '25'", "", DataViewRowState.CurrentRows);
dgtest2.ItemsSource = new DataView(dttest1, "Typeid = '25'", "", DataViewRowState.CurrentRows);
However this seems a little strange. If the Typeid field contains numbers it should be defined as a numeric datatype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With