Click here to Skip to main content
15,886,724 members
Home / Discussions / C#
   

C#

 
GeneralRe: Add column to excel Pin
Estys4-May-10 21:07
Estys4-May-10 21:07 
QuestionReg: Crystal Report Pin
Dotnetkanna4-May-10 19:21
Dotnetkanna4-May-10 19:21 
AnswerRe: Reg: Crystal Report Pin
Eddy Vluggen4-May-10 23:27
professionalEddy Vluggen4-May-10 23:27 
GeneralRe: Reg: Crystal Report Pin
Dotnetkanna5-May-10 0:17
Dotnetkanna5-May-10 0:17 
GeneralRe: Reg: Crystal Report Pin
Eddy Vluggen5-May-10 0:56
professionalEddy Vluggen5-May-10 0:56 
GeneralRe: Reg: Crystal Report Pin
Dotnetkanna5-May-10 2:56
Dotnetkanna5-May-10 2:56 
GeneralRe: Reg: Crystal Report Pin
Eddy Vluggen5-May-10 5:00
professionalEddy Vluggen5-May-10 5:00 
QuestionINotifyPropertyChanged Question. Pin
Siddhartha S.4-May-10 19:04
Siddhartha S.4-May-10 19:04 
Hi Experts,

I was really excited when I learned the usage of INotifyPropertyChanged interface. It made binding a bliss and the UI highly interactive and dynamic for me. But then with every problem comes a solution and more problems.
I will explain my question with an example. I have a student class.

public class Student : INotifyPropertyChanged
   {       
           const int MINIMUM_AGE = 1;
           int rollNumber = 0;
           int age = 0;
           string studentName = string.Empty;
    
           #region INotifyPropertyChanged Members
           public event PropertyChangedEventHandler PropertyChanged;
           #endregion
    
           public Student() { }
           public Student(string studentName, int age, int rollNumber)
           {           
               this.StudentName = studentName;
               this.StudentAge = age;
               this.RollNumber = rollNumber;
           }
    
           public string Name
           {
               get
               {
                   return this.studentName;
               }
               set
               {
                   if (value != this.studentName)//guard clause
                   {
                       if (value.Trim() == string.Empty)
                           throw new Exception("Name assigned does not confirms to the format. Please assign a proper alphanumeric value.");
                       this.studentName = value;
                       this.DisplayPropertyChange("StudentName");
                   }
               }
           }
    
           public int StudentAge
           {
               get
               {
                   return this.age;
               }
               set
               {
                   if (value != this.age)//guard clause
                   {
                       //any value lesss than minumum age goes to minimum ages.
                       if (value < MINIMUM_AGE)
                           this.age = MINIMUM_AGE;                                   
                       else
                           this.age = value;
                        this.DisplayPropertyChange("StudentAge");
                   }
               }
           }
    
           public int RollNumber
           {
               get
               {
                   return this.rollNumber;
               }
               set
               {
                   if (value != this.rollNumber)//guard clause
                   {
                       if (value < 0)
                           throw new Exception("Wrong value supplied. Only non negative integers allowed.");
                       this.rollNumber = value;
                       this.DisplayPropertyChange("RollNumber");
    
                   }
               }
           }
    
           void DisplayPropertyChange(string propertyName)
           {
               if (null!=this.PropertyChanged)
               {
                   this.PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
               }
           }        
   }


So far so good. Binding to any of the property would reflect the change in the bound object.
Now, in the same class a property type is a complex/user defined type. Then how are we going to handle it.?e.g.
say in the above class the Name property is changed to the following class instead of string:

public class StudentName
 {
       string firstName = string.Empty;
       string lastName = string.Empty;

       public string FirstName
       {
           get { return firstName; }
           set { firstName = value; }
       }
       public string LastName
       {
           get { return lastName; }
           set { lastName = value; }
       }

       public string FullName
       {
           get { return String.Concat(this.firstName," ",this.lastName); }
       }
       //Default
       public StudentName()
       {}
       //Overloaded
       public StudentName(string firstName, string lastName)
       {
           this.firstName = firstName;
           this.lastName = lastName;
       }
}


And I would access it with something like:
Student student=new Student();
  string.Format("The student's name is {0}",student.Name.FullName);


I implemented the INotifyPropertyChanged interface in the class StudentName too. But the change is still not getting reflected automatically.
IF INotifyPorpertyChanged is not extendable for complex property is there some workaround?
Or am I overlooking some Object Oriented Concept here?
Any help will be highly appreciated.
Best Regards,
Sid

AnswerRe: INotifyPropertyChanged Question. Pin
Dan Mos4-May-10 19:19
Dan Mos4-May-10 19:19 
AnswerRe: INotifyPropertyChanged Question. Pin
AspDotNetDev4-May-10 19:57
protectorAspDotNetDev4-May-10 19:57 
QuestionUsing List for combo box collection [modified] Pin
mprice2144-May-10 17:53
mprice2144-May-10 17:53 
AnswerRe: Using List for combo box collection Pin
Luc Pattyn4-May-10 18:19
sitebuilderLuc Pattyn4-May-10 18:19 
GeneralRe: Using List for combo box collection Pin
mprice2144-May-10 18:40
mprice2144-May-10 18:40 
GeneralRe: Using List for combo box collection Pin
Dan Mos4-May-10 18:56
Dan Mos4-May-10 18:56 
QuestionCalibration and Tolerance Pin
jokerleo4-May-10 17:32
jokerleo4-May-10 17:32 
AnswerRe: Calibration and Tolerance Pin
Luc Pattyn4-May-10 18:21
sitebuilderLuc Pattyn4-May-10 18:21 
GeneralRe: Calibration and Tolerance Pin
jokerleo4-May-10 20:11
jokerleo4-May-10 20:11 
GeneralRe: Calibration and Tolerance Pin
Luc Pattyn5-May-10 2:44
sitebuilderLuc Pattyn5-May-10 2:44 
GeneralRe: Calibration and Tolerance Pin
Dave Kreskowiak5-May-10 4:22
mveDave Kreskowiak5-May-10 4:22 
QuestionReading standardoutput to a file Pin
svanwass4-May-10 14:06
svanwass4-May-10 14:06 
AnswerRe: Reading standardoutput to a file Pin
Dan Mos4-May-10 14:54
Dan Mos4-May-10 14:54 
GeneralRe: Reading standardoutput to a file Pin
svanwass4-May-10 15:00
svanwass4-May-10 15:00 
GeneralRe: Reading standardoutput to a file Pin
Dan Mos4-May-10 16:21
Dan Mos4-May-10 16:21 
GeneralRe: Reading standardoutput to a file Pin
Luc Pattyn4-May-10 16:37
sitebuilderLuc Pattyn4-May-10 16:37 
GeneralRe: Reading standardoutput to a file Pin
Dan Mos4-May-10 16:51
Dan Mos4-May-10 16:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.