Click here to Skip to main content
15,900,906 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
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

C#
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.
Posted
Updated 25-Aug-13 19:52pm
v2
Comments
Jameel VM 23-Aug-13 7:50am    
Crazyy..question...can you post the code?
BillWoodruff 23-Aug-13 21:54pm    
You need to Tag this question: you imply you are running in a browser: is this ASP.NET ?

And, you need to clarify and simplify the question. What are you doing now to detect a change in Property P1? Show us some code.
Brian Holsen 26-Aug-13 7:16am    
I don't quite understand.
Do you mean that, if P1 is changed, P2 will be changed, and also, P2->P3, P3->P4, but not in the inverse order?
Zafar248 29-Aug-13 0:51am    
Exactly.

1 solution

Try this out:
C#
private string _P1;
private int _P2;
private int? _P3
private double? _P4;

public string P1
{
    get{return _P1;}
    set
    {
        _P1=value;
        OnPropertyChanged("P1");
        P2 = ..... // Set P2 value.
    }
}

public int P2
{
    get{return _P2;}
    set
    {
        _P2=value;
        OnPropertyChanged("P2");
        P3 = ..... // Set P3 value.
    }
}

public int? P3
{
    get{return _P3;}
    set
    {
        _P3=value;
        OnPropertyChanged("P3");
        P4 = ..... // Set P4 value.
    }
}
public double? P4
{
    get{return _P4;}
    set
    {
        _P3=value;
        OnPropertyChanged("P4");
    }
}



You'd better post your not-working code out.
 
Share this answer
 
Comments
Zafar248 2-Sep-13 7:12am    
It is the same logic that i asked in my question but it is not working. Sorry for the late reply, switched to some other task in the previous days.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900