Álvaro García
Álvaro García

Reputation: 19356

WPF: how to pass value of cell datagrid to textBox after editing

I have a WPF view (I use MVVM pattern) with a datagrid and some textBox, each textBox has the information of a cell of the dataGrid.

I would like to know, if a I edit a cell in the dataGrid, pass the new value to the textBox, to have in sync the textBox with the dataGrid.

I try the CellEditEnding event, but at this point, I have the old value.

How can I pass the new value to the textBox?

Thanks. Daimroc.

Upvotes: 0

Views: 1595

Answers (2)

Sebastian Edelmeier
Sebastian Edelmeier

Reputation: 4157

The easiest way is to bind the TextBox to the Cell and have the bindings do the refreshing. For this, you will have to set the UpdateSourceTrigger of each Cell to PropertyChanged. See here

Upvotes: 1

Lyuben Todorov
Lyuben Todorov

Reputation: 14153

You could use the SelectionChanged event to update the value of the textbox whenever a value in the data grid changes.

private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    textBox1.Text = "test";
}

And you specify what cell's value should be placed in the textbox.

Upvotes: 1

Related Questions