Hi,
I have a class A, it has properties P1 string, P2 int, P3 int, P4 double, lstB<'B'>, lstC<'C'>, lstD<'D'> and nested classes B,C and D. Now on property change of P1 I have selected values from lstB and assigned them as sources for my gird's combo box column and selected value is binded to P2, same goes for P3-lstC and P4-lstD, Now for the first time I want to set P2 equal to first value in the source and same for P3 and P4 but doing that gets the system in deadlock and I have to close my browser and re-run the application. Thanks in advance.
Zafar
public class A : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private ObservableCollection<BModel> _BList = new ObservableCollection<BModel>();
private ObservableCollection<CModel> _CList = new ObservableCollection<CModel>();
private string _P1;
private int _P2;
private int? _P3;
private double? _P4;
public string P1
{
get { return _P1; }
set
{
_P2 = value;
OnPropertyChanged("P1");
}
}
public int? P2
{
get { return _P2; }
set
{
_P2 = value;
OnPropertyChanged("P2");
}
}
public int? P3
{
get { return _P3; }
set
{
_P3 = value;
IsDirty = true;
P4 = (from r in _lstrate where r.VATCodeId == this.VATCodeId && r.VATListId == this.VATListId select r.Rate).FirstOrDefault();
OnPropertyChanged("P3");
}
}
public double? P4
{
get { return _P4; }
set
{
_P4 = value;
OnPropertyChanged("P4");
}
}
public IEnumerable<BModel> AvailableAList
{
get
{
return from v in _BList where v.P1 == this.P1 select v;
}
}
public IEnumerable<CModel> AvailableBList
{
get
{
return from c in _CList where c.P2 == this.P2 select c;
}
}
public A(string p1, int p2, int? p3, double? p4,
ObservableCollection<BModel> bList, ObservableCollection<CModel> cList)
{
this._P1 = p1;
this._P2 = p2;
this._P3 = p3;
this._P4 = p4;
this._BList = bList;
this._CList = cList;
}
public void OnPropertyChanged(string name)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(name));
}
}
public class BModel
{
public int P2
{
get;
set;
}
public string P2Code
{
get;
set;
}
public string P1
{
get;
set;
}
public BModel(int p2, string p2code, string p1)
{
this.P2 = p2;
this.P2Code = p2code;
this.P1 = p1;
}
}
public class CModel
{
public int P3
{
get;
set;
}
public string P3Code
{
get;
set;
}
public int P2
{
get;
set;
}
public CModel(int p3, string p3code, int p2)
{
this.P3 = p3;
this.P3Code = p3Code;
this.P2 = p2;
}
}
}
this code is working fine, but if I try to set values of P2 on change of P1 and P3 on change of P2 and P4 on change of P3, then the system does not respond.