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 Telerik.Windows.Controls;
using Telerik.Windows.Controls.GridView;

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

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            for (int columnIndex = 0; columnIndex < 10; columnIndex++)
                radGridView1.Columns.Add(new CustomColumn() 
                { 
                    ColumnIndex = columnIndex, Width = 125, CellStyleSelector = this.Resources["styleSelector"]as StyleSelector 
                });

            List<GridItem> items = GridItem.GetItems();
            radGridView1.ItemsSource = items;
        }
    }

    public class CustomColumn : GridViewBoundColumnBase
    {
        public int ColumnIndex { get; set; }

        public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
        {
            if (cell == null) return base.CreateCellElement(cell, dataItem);
            // Data item
            GridItem gridDataItem = (GridItem)dataItem;
            TextBlock textBlock = new TextBlock();
            textBlock.Text = gridDataItem.Columns[ColumnIndex];
            return textBlock;
        }

        public override FrameworkElement CreateCellEditElement(GridViewCell cell, object dataItem)
        {
            if (cell == null) return base.CreateCellEditElement(cell, dataItem);

            TextBox textBox = new TextBox();
            textBox.Text = ((GridItem)dataItem).Columns[ColumnIndex];
            return textBox;
        }
    }

    public class GridItem
    {
        public static List<GridItem> GetItems()
        {
            List<GridItem> items = new List<GridItem>();

            for (int rowIndex = 0; rowIndex < 50; rowIndex++)
            {
                GridItem item = new GridItem();
                item.Index = rowIndex;

                for (int columnIndex = 0; columnIndex < 10; columnIndex++)
                {
                    item.Columns.Add(string.Format("Row{0}, Column{1}", rowIndex + 1, columnIndex + 1));
                }

                items.Add(item);
            }

            return items;
        }

        public int Index;
        public List<string> Columns = new List<string>();
    }
}
