WPF Datagrid set the column values only when the row is left
Posted
by Noam
on Stack Overflow
See other posts from Stack Overflow
or by Noam
Published on 2010-03-20T16:29:07Z
Indexed on
2010/03/20
16:31 UTC
Read the original article
Hit count: 572
Hello
I have a simple class. When I use it in winforms binding, whenever I change a value of a cell and leave the cell, the property immediately get changed. Using WPF Datagrid, whenever i change a value of a cell, the property gets set only after I leave the row. That is problematic for me. What am I doing wrong?
Here is my code:
public class MyClass : IEditableObject, INotifyPropertyChanged
{
string _name, _lastName;
public string Name
{
get { return _name; }
set
{
_name = value;
_lastName = value + " xxx";
OnPropertyChanged("LastName");
MessageBox.Show("Test");
}
}
private void OnPropertyChanged(string p)
{
var x = new PropertyChangedEventArgs(p);
if (PropertyChanged != null)
PropertyChanged(this, x);
}
public string LastName { get { return _lastName; } set { _lastName = value; } }
public void BeginEdit()
{
}
public void CancelEdit()
{
}
public void EndEdit()
{
}
public event PropertyChangedEventHandler PropertyChanged;
}
public class myBindingList : BindingList<MyClass>
{
public myBindingList()
{
AllowNew = true;
Add(new MyClass { Name = "noam" });
Add(new MyClass { Name = "yael" });
}
}
© Stack Overflow or respective owner