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

[Solved] Strange DataContext for GridViewRowItem

4 Answers 128 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andreas
Top achievements
Rank 1
Andreas asked on 27 Jun 2011, 08:14 AM
Hi,

I have a RadGridView defined as follows:
<grid:RadGridView x:Name="externalListGrid"
 HorizontalAlignment="Stretch"
 VerticalAlignment="Stretch"
 AutoGenerateColumns="False"
 IsReadOnly="True"
 ItemsSource="{Binding Rows}"
 SelectionMode="{Binding SelectionMode}"
 ShowGroupPanel="False"
 IsSynchronizedWithCurrentItem="True" >
                    
 <i:Interaction.Behaviors>
  <behaviors:DataGridRowDoubleClickBehavior/>
 </i:Interaction.Behaviors>
 
</grid:RadGridView>

In the Behavior I react on the RowLoaded event of the grid. RowLoadedEventArgs contain a Row which should be of type GridViewRowItem. But actually it returns a GridViewHeaderRow with a strange DataContext. Namely the context of the Grid (in my case some ViewModel) and not the actual context of the row. So I have the problem that there is no connection to the actual row which was loaded.

Is this the expected bahavior?

Kind regards,
Stefan

4 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 27 Jun 2011, 08:16 AM
Hello Stefan,

 Indeed RowLoaded will be fired for the header row as well and the DataContext of the header row is not related to data-items. 

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
0
Andreas
Top achievements
Rank 1
answered on 27 Jun 2011, 09:57 AM
Hi Vlad,

I wanted to use the RowLoaded-Event to set some rows initially selected depending on a IsSelected-Flag in the object which is the DataContext of the row. What is the best way to do so instead?

Thanks,
Stefan
0
Accepted
Pavel Pavlov
Telerik team
answered on 27 Jun 2011, 04:19 PM
Hi Stefan,

Your approach is ok . You will just need to check for the case when the header row raises the event. Usually this would be only the first call of the handler. The next ones will be for the 'real ' rows . So a single if statement , to check if this is a header row -> do nothing , else -> set ischecked...should do the trick.

Best wishes,
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
0
Andreas
Top achievements
Rank 1
answered on 28 Jun 2011, 12:20 PM
Hi,

thanks for your help. Works great.

Stefan
Tags
GridView
Asked by
Andreas
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Andreas
Top achievements
Rank 1
Pavel Pavlov
Telerik team
Share this question
or