21 February 2007

INotifyPropertyChanged Interface

Sometimes in my applications I use some binding mechanism. It helps me to build the huge forms. To show the way how it works at the begging I will create a small class Person which contains one property Surname linking with textbox.

public class Person

{

private string _surname;

public string Surname

{

get { return this._surname; }

set { this._surname = value; }

}


public Person(string surname)

{

this._surname = surname;

}

}

Next step is creating a new form on which will be placed the earlier mentioned textbox control. After that we have to simply override the OnLoad method.

protected override void OnLoad(EventArgs e)

{

base.OnLoad(e);

this.textBox1.DataBindings.Add("Text", this.p, "Surname");

}


Ok it is done. We can test it. Everything look quite nice, but what would happen if we change the p.Surname during application is running. Nothing. That's the problem the changes are not affected if we change the property Surname. To fix it we have to equip our Person class with INotifyPropertyChanged interface. This interface will add a new event to our class body. So if we have a new event We must use it.

public string Surname

{

get { return this._surname; }

set

{

this._surname = value;

if ( this.PropertyChanged != null)

this.PropertyChanged(this, new PropertyChangedEventArgs("Surname"));

}

}


Now when we start the application and we change Surname property we will find out that the textbox control has been changed too. That is what we wanted. Notice that PropertyChangedEventArgs constructor takes one string arg "PropertyName". This argument should be exact name of the property which is already changing.
Good luck

14 February 2007

Valentin's day

This day is good day for writing something about my private live especially my wife. The 10th June 2006 is a day when once in my life I was sure of what I had said. On this day I said "Yes" which meant that I want to spend my whole live with me wife - Aga.Since this time I have never regret my decision, oops! maybe once but not any more. It was day after married when I could not be on my last exam, so I got bad note, but after this time was only flours and butterflies. :) Currently we live in small town where is about 20k people. You can see our building here. This place is great everywhere is near and only familiar faces.
I love taking pictures so below I place my Aga picture.



And another one :)



ko
.ci.

It's almost over ...

A sigh of relief.
For about six months I have been making my own Engineering thesis. It consists of program and theory document. The program is written in .NET (C#) and based on Microsoft SQL Server 2005. The main thing which it does, is tracking working-hours of company stuff and registering them into database.(I will bring closer this application soon on blog with screenshots and pieces of code) The second part is pure text with couples screenshots and some UML charts. I sent my last part of Engineering thesis to my professor couple days ago. Currently I look forward to having any response from him to correct some small details and I will be ready to defend it. I think I will get my Engineering degree in march.