When I edit in the Datagrid a value, the value in the Textbox should also immediately change and not when I leave the row.
Here the code:
<Window x:Class="WpfApplication_Xceed.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" xmlns:my="clr-namespace:Xceed.Wpf.DataGrid;assembly=Xceed.Wpf.DataGrid">
<Grid Height="400" Width="800
">
"BeginEditCommand, ClickOnCurrentCell, ActivationGesture" CellEditorDisplayConditions="Always" HorizontalAlignment="Right" Width="334" />
<TextBox Height="23" HorizontalAlignment="Right" Margin="0,0,219,92"
Name="textBox1" VerticalAlignment="Bottom" Width="120" />
</Grid>
</
Window>
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Data;
using
System.Windows.Documents;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Imaging;
using
System.Windows.Navigation;
using
System.Windows.Shapes;
using
System.Collections;
using
System.ComponentModel;
namespace
WpfApplication_Xceed
{
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
List<MyDataClass> list2 = new List<MyDataClass>();
list2.Add(
new MyDataClass { ValueA = " Test 1" });
list2.Add(
new MyDataClass { ValueA = " Test 2" });
list2.Add(
new MyDataClass { ValueA = " Test 3" });
dataGridControl2.ItemsSource =
CollectionViewSource.GetDefaultView(list2);
Binding myBinding = new Binding("ValueA");
myBinding.Source =
CollectionViewSource.GetDefaultView(list2);
textBox1.SetBinding(
TextBox.TextProperty, myBinding);
}
}
public class MyDataClass : INotifyPropertyChanged
{
// Declare the event
public event PropertyChangedEventHandler PropertyChanged;
private string valueA;
public string ValueA
{
get { return valueA; }
set
{
valueA =
value;
// Call OnPropertyChanged whenever the property is updated
OnPropertyChanged(
"ValueA");
}
}
public override string ToString()
{
return ValueA;
}
// Create the OnPropertyChanged method to raise the event
protected void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(
this, new PropertyChangedEventArgs(name));
}
}
}
}