Creating custom control for Gridview

2 posts, 0 answers
  1. Gopinath
    Gopinath avatar
    63 posts
    Member since:
    Sep 2011

    Posted 06 Apr 2012 Link to this post

    I have created a custom control for GridView as shown below

    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 SilverlightApplication1
    {
        public class AuthGrid : RadGridView
        {
            public AuthGrid()
            {
                this.DefaultStyleKey = typeof(AuthGrid);
            }


            #region ItemsSource


            public Object ItemsSource
            {
                get
                {
                    return (Object)GetValue(ItemsSourceProperty);
                }
                set
                {
                    if (value != ItemsSource) SetValue(ItemsSourceProperty, value);
                }
            }
            // Using a DependencyProperty as the backing store for DisplayMemberPath.  This enables animation, styling, binding, etc...
            public static readonly DependencyProperty ItemsSourceProperty =
                DependencyProperty.Register("ItemsSource", typeof(Object), typeof(AuthGrid), new PropertyMetadata(new PropertyChangedCallback(OnItemSourcecPropertyChanged)));


            private static void OnItemSourcecPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                //
                var AuthGrid = d as AuthGrid;


                if (AuthGrid != null)
                {
                    AuthGrid.ItemsSource = e.NewValue as Object;
                }
            }


            #endregion
        }
    }


    Finally i used that in my page as shown below

     <local:AuthGrid x:Name="RadGridView1" ScrollMode="Deferred"  ItemsSource="{Binding Source={StaticResource DataSource}, Path=Agency}"
    IsReadOnly="True" AutoGenerateColumns="True" MinHeight="386" MaxHeight="500"
    CanUserFreezeColumns="False" RowIndicatorVisibility="Collapsed" CanUserResizeColumns="False">
                </local:AuthGrid>


    • When i placed the custom control in my page. I didn't see the Grid in the design page. 
    • Secondly the data not binded to the grid view .

    If i am wrong in creating a custom control and Dependency properties
    can you please provide me the sample project for Creating Custom control for Grid view





  2. Wan
    Wan avatar
    10 posts
    Member since:
    Mar 2012

    Posted 18 Apr 2012 Link to this post

    I meet the same problem now.  Anyone can help us ?  Thanks!
  3. DevCraft banner
Back to Top