This is a migrated thread and some comments may be shown as answers.

Getting GridViewRowItem on SelectionChanged

4 Answers 323 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeffrey Lewis
Top achievements
Rank 1
Jeffrey Lewis asked on 19 May 2010, 11:14 AM
How do I get the GridViewRowItem object of the selected row in the RadGrid SelectionChanged event?


4 Answers, 1 is accepted

Sort by
0
Accepted
Yavor Georgiev
Telerik team
answered on 19 May 2010, 12:13 PM
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.
0
Jeffrey Lewis
Top achievements
Rank 1
answered on 20 May 2010, 02:03 AM
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.

0
Yavor Georgiev
Telerik team
answered on 20 May 2010, 12:35 PM
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.
0
Jeffrey Lewis
Top achievements
Rank 1
answered on 21 May 2010, 02:49 AM
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.
Tags
GridView
Asked by
Jeffrey Lewis
Top achievements
Rank 1
Answers by
Yavor Georgiev
Telerik team
Jeffrey Lewis
Top achievements
Rank 1
Share this question
or