using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using Telerik.Windows.Controls;

namespace multiColumnCombo_SL
{
	public partial class MainPage : UserControl
	{
		public MainPage()
		{
			InitializeComponent();

			List<Person> persons = new List<Person>();
			persons.Add(new Person(1,"Carlos"));
			persons.Add(new Person(2, "Hans"));
			persons.Add(new Person(3, "Pierre"));

			this.RadGridView1.ItemsSource = persons;
			((GridViewComboBoxColumn)this.RadGridView1.Columns[1]).ItemsSource = GetCountries();
		}

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

			return countries;
		}

		private List<Country> GetCountries2()
		{
			List<Country> countries = new List<Country>();
			countries.Add(new Country(1,"Japan" ));
			countries.Add(new Country(2,"China" ));
			countries.Add(new Country(3,"Korea" ));

			return countries;
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			((GridViewComboBoxColumn)this.RadGridView1.Columns[1]).ItemsSource = GetCountries2();
		}
	}

	public class Country
	{
		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;
			}
		}
		private string name;
		public string Name 
		{
			get
			{
				return this.name;
			}
			set
			{
				this.name = value;
			}
		}
	}

	public class Person : INotifyPropertyChanged
	{
		public Person( int countryID, string name)
		{
			this.Name = name;
			this.CountryID = countryID;
		}

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


		public event PropertyChangedEventHandler PropertyChanged;

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

	}
}
