Getting GridViewRowItem on SelectionChanged

5 posts, 1 answers
  1. Jeffrey Lewis
    Jeffrey Lewis avatar
    8 posts
    Member since:
    Apr 2010

    Posted 19 May 2010 Link to this post

    How do I get the GridViewRowItem object of the selected row in the RadGrid SelectionChanged event?


  2. Answer
    Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 19 May 2010 Link to this post

    Hi Jeffrey Natheniel Lewis,

     What  you can do is 

    var row = this.radGridView.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]) as GridViewRowItem;

    in your event handler.

    Sincerely yours,
    Yavor Georgiev
    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. Jeffrey Lewis
    Jeffrey Lewis avatar
    8 posts
    Member since:
    Apr 2010

    Posted 19 May 2010 Link to this post

    Hi Yavor Georgiev,

    The value returned from ContainerFromItem is null. I've checked to confirm that e.AddedItems[0] has value in it (of type DataRow).

    The following is my code (My ItemsSource is a DataTable):

    ----------------------------------------------------------------------
    DataTable dtFeeds = GetFeeds();
    this.radGridFeeds.ItemsSource = dtFeeds;

    ----------------------------------------------------------------------
    private void radGridFeeds_SelectionChanged(object sender, SelectionChangeEventArgs e)
    {
    var row = this.radGridFeeds.ItemContainerGenerator.ContainerFromItem(e.AddedItems[0]) as GridViewRowItem;
    }


    Please asist. Thanks.

  5. Yavor Georgiev
    Admin
    Yavor Georgiev avatar
    982 posts

    Posted 20 May 2010 Link to this post

    Hello Jeffrey,

     Please find attached a sample solution. If  you still have troubles, please consider preparing a sample solution yourself, along with your Telerik assemblies, that demonstrates the incorrect behavior.

    Sincerely yours,
    Yavor Georgiev
    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. Jeffrey Lewis
    Jeffrey Lewis avatar
    8 posts
    Member since:
    Apr 2010

    Posted 20 May 2010 Link to this post

    Thank you very much for the solution. My problem is solved.

    I have noticed that when the radgrid's IsSynchronizedWithCurrentItem property is true, the first record selected(by default) always returns a null value from ContainerFromItem. To solve this, I've set the IsSynchronizedWithCurrentItem to false, and manually select the default record in the Loaded event.
Back to Top
UI for WPF is Visual Studio 2017 Ready