DataGrid refresh one cell from another

Nov 14, 2008 at 5:40 PM
I've got a DataGrid bound to an ObservableCollection<T>, and two columns bound to different properties of T, propA and propB. The T class implements IPropertyNotifyChanged.

Now, the value of propB is dependent on the value of propA.
When I edit the propA column, it correctly updates the value of the bound propA property in T.

I would like to force the propB column to refresh itself, to show the new value of propB.
Any ideas?
Nov 14, 2008 at 11:31 PM
You will have to call a BindingExpression.UpdateTarget on the FrameworkElement of the DataGridCell.Content that you want to update.
Nov 18, 2008 at 1:56 PM
thanks - I've got the BindingExpression.UpdateTarget to work OK for a DataGridTextColumn - I'm firing it in a CellEditEnding event handler;

    DataGridRow row = e.Row;
presenter = GetVisualChild<DataGridCellsPresenter>(row);
    DataGridCell cell = (DataGridCell)presenter.ItemContainerGenerator.ContainerFromIndex(2); // get fac value cell
    TextBlock textBlock = cell.Content as TextBlock;
    BindingExpression be = textBlock.GetBindingExpression(TextBlock<spantextblock< />.TextProperty);
I'm struggling a bit to find the appropriate syntax for a DataGridTemplateColumn though...













Nov 18, 2008 at 5:15 PM
You can do something like this:



cell = Helper.GetCell(DataGrid_Standard, rowIndex, colIndex);
TextBlock tb = Helper.GetVisualChild<TextBlock>(cell);


You can find the code for these helper functions in the sample on this post,

Dec 3, 2008 at 4:30 PM
Edited Dec 3, 2008 at 4:45 PM
When I set the values to the TextBlock as shown above the DataGridColumn doesn't show the value immediately
When I set the values direct to cell.Content the values show up immediately , but they are vertically aligned at the top.

How can I archieve a vertically centered alignment ?

Sorry - solved my problem - works perfect!
Jan 5, 2009 at 10:44 PM
I'm a beginner with WPF/datagrid. I need to do something like what's described in original post here - when adding a row, I need to display a a combobox in the first column and based on selection (property A of object T), I need to show property B in the textbox in column 2. Can you, please "dumb-down" how exactly I can achieve that? If you can point me to some example, that would be terrific. I got my grid bounded to the ObservableCollection<T> object. Do I need to include IPropertyNotifyChanged for that object as well?

Thanks in advance!