using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;
using Telerik.Windows.Controls.GridView;
using Telerik.Windows.Controls;

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

        private void RadGridView_Loaded(object sender, RoutedEventArgs e)
        {
            gridView.ItemsSource = new ObservableCollection<Person>
            {
                new Person(){FirstName="John",LastName="Dow",JobName="AD"},
                new Person(){FirstName="John",LastName="Dow",JobName="AD"},
                new Person(){FirstName="John",LastName="Dow",JobName="AD"},
                new Person(){FirstName="John",LastName="Dow",JobName="AD"},
                new Person(){FirstName="John",LastName="Dow",JobName="AD"},
                new Person(){FirstName="John",LastName="Dow",JobName="AD"},
                new Person(){FirstName="John",LastName="Dow",JobName="AD"}
            };
            ((GridViewComboBoxColumn)gridView.Columns["Job"]).ItemsSource = new List<Job>
            {
                new Job(){Name="AD"},
                new Job(){Name="BD"},
                new Job(){Name="CD"},
                new Job(){Name="DD"},
                new Job(){Name="ED"}
            };
        }

        private void gridView_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
            if (e.Row is GridViewRow)
            {
                foreach (var cell in e.Row.Cells)
                {
                    cell.MouseEnter += new MouseEventHandler(cell_MouseEnter);
                    cell.MouseLeave += new MouseEventHandler(cell_MouseLeave);
                }
            }
        }

        void cell_MouseLeave(object sender, MouseEventArgs e)
        {
            GridViewCell cell = sender as GridViewCell;
            if (cell != null && cell.IsInEditMode)
            {
                cell.CommitEdit();
            }
        }

        void cell_MouseEnter(object sender, MouseEventArgs e)
        {
            GridViewCell cell = sender as GridViewCell;
            if (cell != null)
            {
                cell.BeginEdit();
            }
        }


    }

    public class Person
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string JobName { get; set; }

    }

    public class Job
    {
        public string Name { get; set; }
    }
}
