using System.Collections.Generic;
using System.Windows;
using System.ComponentModel;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls;

namespace ComboBocColumn_WPF
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{
		public MainWindow()
		{
			InitializeComponent();

			this.RadGridView1.ItemsSource = Person.GetNames();
			((GridViewComboBoxColumn)this.RadGridView1.Columns[1]).ItemsSource = Country.GetCountries();
		}
	}

	public class Person : INotifyPropertyChanged
	{
		private string name;
		private int countryID;

		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				if (this.name != value)
				{
					this.name = value;
					this.OnPropertyChanged("Name");
				}
			}
		}

		private int age;

		public int Age
		{
			get
			{
				return this.age;
			}
			set
			{
				this.age = value;
				this.OnPropertyChanged("Age");
			}
		}

		public int CountryID
		{
			get
			{
				return this.countryID;
			}
			set
			{
				if (this.countryID != value)
				{
					this.countryID = value;
					this.OnPropertyChanged("CountryID");
				}
			}
		}

		public Person()
		{
		}

		public Person(string name, int countryID, int age)
		{
			this.name = name;
			this.countryID = countryID;
			this.age = age;
		}

		public static ObservableCollection<Person> GetNames()
		{
			ObservableCollection<Person> names = new ObservableCollection<Person>();

			names.Add(new Person("Adam Debrovski", 1, 14));
			names.Add(new Person("Juames Peterson", 2, 16));
			names.Add(new Person("Vladislav Znekovski", 3, 17));
			names.Add(new Person("Peter Borisov", 2, 23));
			names.Add(new Person("John Peterson", 2, 45));

			return names;
		}

		public event PropertyChangedEventHandler PropertyChanged;

		void OnPropertyChanged(string property)
		{
			if (this.PropertyChanged != null)
				this.PropertyChanged(this, new PropertyChangedEventArgs(property));
		}
	}

	public class Country : INotifyPropertyChanged
	{
		public Country(int id, string name)
		{
			this.Name = name;
			this.id = id;
		}

		private int id;

		public int ID
		{
			get
			{
				return this.id;
			}
			set
			{
				this.id = value;
				this.OnPropertyChanged("ID");
			}
		}

		private string name;

		public string Name
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
				this.OnPropertyChanged("Name");
			}
		}

		private List<Country> countries;

		public List<Country> Countries
		{
			get
			{
				return GetCountries();
			}
		}

		public Country()
		{
		}

		public override string ToString()
		{
			return name;
		}

		public static List<Country> GetCountries()
		{
			List<Country> countries = new List<Country>();
			countries.Add(new Country(1, "Spain"));
			countries.Add(new Country(2, "Germany"));
			countries.Add(new Country(3, "France"));

			return countries;
		}

		public event PropertyChangedEventHandler PropertyChanged;

		void OnPropertyChanged(string property)
		{
			if (this.PropertyChanged != null)
				this.PropertyChanged(this, new PropertyChangedEventArgs(property));
			//	MessageBox.Show("the value has been changed and now it is: " + Name);
		}
	}
}
