using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.IO;
using System.Diagnostics;
using System.Collections.Specialized;
using Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;
using System.Windows.Controls;

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

            RadGridView1.ItemsSource = from i in Enumerable.Range(0, 10)
                                       select new MyObject() { ID = i, Name = String.Format("Name{0}", i) };

            RadGridView1.RowLoaded += new EventHandler<RowLoadedEventArgs>(RadGridView1_RowLoaded);
        }

        void RadGridView1_RowLoaded(object sender, RowLoadedEventArgs e)
        {
            if (!(e.Row is GridViewHeaderRow) && !(e.Row is GridViewNewRow) && 
                e.Row.ContextMenu == null)
            {
                e.Row.ContextMenu = (ContextMenu) RadGridView1.Resources["MyContextMenu"];
            }
        }

        private void ContextMenu_Opened(object sender, RoutedEventArgs e)
        {
            GridViewRow row = ((ContextMenu) sender).PlacementTarget as GridViewRow;
            if (row != null)
            {
                row.IsSelected = true;
            }
        }
    }

    public class MyObject
    {
        public int ID { get; set; }
        public string Name { get; set; }
    }
}
