DataView FilterExpresion Issue

G

Guest

I'm using a dataview as datasource for a datagrid and it's is filtering and sortering the data Ok
The problem happens when I try to update one of the data view rows and the column I am updating is part of the filter expression. For instance, if I'm filtering my datagrid by 'Salesman A', when I change the value of one of the datagrid rows to 'Salesman B', this row is no longer in the dataview and that's not what I want. How can I keep the the changed row in the data view? Shall I use RowStateFilter? How?
 
J

Jon Skeet [C# MVP]

Paulo said:
I'm using a dataview as datasource for a datagrid and it's is
filtering and sortering the data Ok.
The problem happens when I try to update one of the data view rows
and the column I am updating is part of the filter expression. For
instance, if I'm filtering my datagrid by 'Salesman A', when I change
the value of one of the datagrid rows to 'Salesman B', this row is no
longer in the dataview and that's not what I want. How can I keep the
the changed row in the data view? Shall I use RowStateFilter? How?

Well, I *think* you could use a RowStateFilter of 38
(Added | Unchanged | ModifiedOriginal) - but don't quote me on that.
 
G

Guest

Well, that keeps my datarow there but I can't edit any other column in this row afterwards. For instance
dv[rowIndex]["Salesman"] = "John" (afects rowfilter
dv.RowStateFilter = DataViewRowState.ModifiedOriginal|DataViewRowState.Unchanged; (keeps the row there
dv[rowIndex]["Customer"] = "Mark" ---> ERRO
System.Data.DataException: Cannot set Customer
 
J

Jon Skeet [C# MVP]

Paulo said:
Well, that keeps my datarow there but I can't edit any other column in this row afterwards. For instance:
dv[rowIndex]["Salesman"] = "John" (afects rowfilter)
dv.RowStateFilter =
DataViewRowState.ModifiedOriginal|DataViewRowState.Unchanged; (keeps
the row there)
dv[rowIndex]["Customer"] = "Mark" ---> ERROR
System.Data.DataException: Cannot set Customer.

Hmm... Of course, it's then trying to set the wrong version.

I think you're basically on a hiding to nothing trying to keep a view
"semi-working".

What you *could* do is have an in-memory column - set something in
there for everything you want to initially see, and then set the
RowFilter to match that.
 
C

Cor Ligthert

Hi Paulo,

Have a look at the datatable.select instead for this.

The rowfilter is dynamic
The select is static

I hope this helps?

Cor
 
G

Guest

Thanks Jen, Thanks Cor
I created a in-memory column in my dataview, as suggested, and I used it to mark the current rows before the update
I then cleared the rowfilter and set it to retrieve only the marked rows
I doubt this is the best solution but it's working fine. Any thoughts
Paul
 
K

Kevin Yu [MSFT]

Hi Paulo,

I think this is the best solution to the problem. Since you're changing the
column that will affect the filter, this solution is much better that just
using the DataView.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top