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

How to access row source data?

1 Answer 74 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Temp
Top achievements
Rank 1
Temp asked on 16 Apr 2010, 05:46 AM

Hi I think this is probably very easy, but I can't seem to find the right method.

I have two columns in the LINQ data source, Rank and PreviousRank.

In a GridViewDataColumn I have an image, and the image needs to be either an up arrow or a down arrow depending on the change of Rank compared to PreviousRank.

So on the image loaded event I have an event, now when I am in the event, how do I access the Rank and PreviousRank of the rows data?

I could bind a value to the image right? But this is only one. I see a DataContext, can I set that so when I am in the image loaded event, I can just access the data source row and go sourcerow.Rank and sourcerow.PreviousRank?

Does this make sense?

            <telerikGridView:RadGridView   
                    x:Name="RadGrid8020"   
                    MinWidth="400" MaxWidth="900" 
                    ShowGroupPanel="false"   
                    CanUserDeleteRows="false"     
                    CanUserFreezeColumns="false" 
                    CanUserInsertRows="false" 
                    CanUserReorderColumns="true" 
                    CanUserResizeColumns="false" 
                    CanUserSelect="true" 
                    CanUserSortColumns="true" 
                    IsReadOnly="true" 
                    AutoGenerateColumns="false" ScrollMode="RealTime" 
                >     
                <telerikGridView:RadGridView.SortDescriptors> 
                    <telerikData:SortDescriptor Member="Rank" SortDirection="Ascending" /> 
                </telerikGridView:RadGridView.SortDescriptors> 
                <telerikGridView:RadGridView.GroupHeaderTemplate> 
                    <DataTemplate> 
                        <TextBlock Foreground="Green" Text="" Loaded="RadGrid8020_TextBlock_Loaded"/>  
                    </DataTemplate> 
                </telerikGridView:RadGridView.GroupHeaderTemplate> 
                <telerikGridView:RadGridView.Columns> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Rank}" Header="Rank" IsFilterable="false" IsSortable="true">  
                        <telerikGridView:GridViewDataColumn.CellTemplate> 
                            <DataTemplate> 
                                <StackPanel Orientation="Horizontal">  

                                    <!--HERE IS THE IMAGE!!!-->
                                    <Image Loaded="RadGrid8020_RankMoveImage_Loaded"/><TextBlock Text="{Binding Rank}"/>  
                                </StackPanel> 
                            </DataTemplate> 
                        </telerikGridView:GridViewDataColumn.CellTemplate> 
                    </telerikGridView:GridViewDataColumn> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding CustomerName}" Header="Client" HeaderTextAlignment="Left" IsFilterable="false" IsSortable="true" TextAlignment="Left" /> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding JobCount}" Header="Job Count" HeaderTextAlignment="Right" IsFilterable="false" IsSortable="true" TextAlignment="Right" DataFormatString="{}{0:n0}" /> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Turnover}" Header="Turnover" HeaderTextAlignment="Right" IsFilterable="false" IsSortable="true" TextAlignment="Right" DataFormatString="{}{0:c2}" /> 
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding AverageJobTurnover}" Header="Avg Per Job" HeaderTextAlignment="Right" IsFilterable="false" TextAlignment="Right" DataFormatString="{}{0:c2}" /> 
                </telerikGridView:RadGridView.Columns> 
            </telerikGridView:RadGridView> 
private void RadGrid8020_RankMoveImage_Loaded(object sender, RoutedEventArgs e)  
        {  
 
              
            //==================================  
            //Need to say   
            //   IF rowdata.RANK < rowdata.PREVIOUSRANK then img = uparrow  
            //  ELSE img = downarrow  
              
            //==================================  
              
            string imgfile = "iconarrowup.png";  
            //string imgfile = "iconarrowdown.png";  
            StreamResourceInfo sr = Application.GetResourceStream(new Uri("ewreportingapp;component/Resources/" + imgfile, UriKind.Relative));  
            BitmapImage bmp = new BitmapImage();  
            bmp.SetSource(sr.Stream);  
            Image img = (Image)sender;  
            img.Source = bmp;  
        } 

1 Answer, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 16 Apr 2010, 06:54 AM
Hi,

Indeed DataContext of the image is your data item - you can cast this to your object type and access desired property.

All the best,
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.
Tags
GridView
Asked by
Temp
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Share this question
or