How to link Datapager and gridview programmatically

6 posts, 1 answers
  1. Kiran
    Kiran avatar
    36 posts
    Member since:
    Jul 2010

    Posted 05 Oct 2010 Link to this post

    Hi

    I am trying to come up with a composite control which includes GridView and Date pager something similar to asp.net grid. I have AllowPagination property. I am finding it difficult as to how link datapager and gridview control in the composite control.

    I have seen the sample where it says Datapager Source="{Binding Items, ElementName=radGridView}" but how i can I do the same linking in code behind.

    Regards
    Kiran
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 06 Oct 2010 Link to this post

    Hi,

     Here is an example:

     
    pager.SetBinding(RadDataPager.SourceProperty, new Binding("Items") { Source = grid });

    Kind regards,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kiran
    Kiran avatar
    36 posts
    Member since:
    Jul 2010

    Posted 11 Oct 2010 Link to this post

    Hi

    Though this works but partially when I add this line of code I can see the datapager is working with but Grid does not show anything do I need to set anything for the grid.

    DataPager.SetBinding(TngDataPager.SourceProperty, new Binding("Items") { Source = GridView });

    Thanks
    Kiran
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 11 Oct 2010 Link to this post

    Hello,

     Can you post how you've set ItemsSource for the grid?

    Best wishes,
    Vlad
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Kiran
    Kiran avatar
    36 posts
    Member since:
    Jul 2010

    Posted 12 Oct 2010 Link to this post

    Hi

    This is how I am using ItemSource property and Allow Paging property. Things seems to work fine when I run the screen first time but if I try to set the Grid ItemSource again my composite control crashes is there anything I need to do to un-bind and re-bind.

    This is how I am trying to set Item Source using code-behind and I get a crash here.

    GridView8.ItemsSource =

     

    TestData.GetDepartments();

     



    #region Property: ItemsSource
    /// <summary>
    /// Items is the collection of data that is used to generate the content of this control.
    /// </summary>
    public Object ItemsSource
    {
        get { return GetValue(ItemsSourceProperty); }
        set { SetValue(ItemsSourceProperty, value); }
    }
    public static readonly DependencyProperty ItemsSourceProperty =
        DependencyProperty.Register(
            "ItemsSource", typeof(Object), typeof(TngGridView),
            new FrameworkPropertyMetadata
            {
                PropertyChangedCallback = (obj, e) =>
                {
                    (obj as TngGridView).UpdateItemsSource(e.NewValue);
                }
            });
    private void UpdateItemsSource(Object sel)
    {
        GridView.ItemsSource = sel;
    }
    #endregion

    Allow Pagin Property is defined likr this.

    #region Property: AllowPaging
    private bool _allowpaging = false;
    /// <summary>
    /// Sets AllowPaging
    /// </summary>
    [DesignOnly(true)]
    public bool AllowPaging
    {
        get { return _allowpaging; }
        set
        {
            _allowpaging = value;
            if (_allowpaging)
            {
                DataPager.Visibility = Visibility.Visible;
                DataPager.SetBinding(TngDataPager.SourceProperty, new Binding("Items") { Source = GridView });
                GridView.SetBinding(TngGridView.ItemsSourceProperty, new Binding("PagedSource") { Source = DataPager });
                  
                  
            }
             }
    }
    #endregion

    Regards
    Kiran
  7. Answer
    Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 13 Oct 2010 Link to this post

    Hello Kiran,

    The proper way for things to work would be as follows :

    Data goes to  Pager.Source

    GridView takes ItemsSource from Pager.PagedSource.

    When new data comes, you need to change the Pager.Source , not RadGridView.ItemsSource.
    And what you do is :
    private void UpdateItemsSource(Object sel)
    {
        GridView.ItemsSource = sel;
    }

    Maybe you need to change the code to update the Pager.Source instead.

    In case this does not do the trick , just send me yuor project and I will do the fixes necessary for you .


    Sincerely yours,
    Pavel Pavlov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready