F
F
frasl2013-02-01 19:46:49
.NET
frasl, 2013-02-01 19:46:49

Data Binding in WPF

There is a WPF DataGrid, it has banal text fields, something like this:

<DataGridTextColumn Header="Азот, т" Binding="{Binding Path=AmountN, Mode=TwoWay}" IsReadOnly="True"></DataGridTextColumn>

An ObservableCollection is attached to it, the element of which is just a class with a set of properties.

The above column is a computed one, and is calculated when the user changes the data in another column, by the CellEditEnding event.

That is, in the event handler, I change some properties in the collection that should be displayed in the grid.

In short, it doesn't happen.

Long story short, if you make a cell writable, then at the moment when editing starts, the data is pulled up - that is, the binding exists and I specified the column name correctly.

Further, I tried to call Items.Refresh () on the grid, but I got an exception saying that this should not be done at the time of editing the cell.
Calling CommitEdit does not change anything, of course.

Question: how to tell the grid that it would be time to update the data in the cells?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
ad1Dima, 2013-02-01
@frasl

I am somewhat confused by Mode=TwoWay and IsReadOnly="True" together.
In general, you need to notify the binding that the property it is bound to has changed. For example, by implementing the INotifyPropertyChanged interface

X
x64, 2013-02-01
@x64

Still, it would be more correct to implement INotifyPropertyChanged. And in general, immediately make a base class with its convenient implementation and drag it everywhere. The rest of the solutions will be in the rank of more / less successful hacks.
Unfortunately, I can’t check it myself, and calls to methods with “Invalidate” in the name don’t help either?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question