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

How to access row source data?

1 Answer 74 Views
This is a migrated thread and some comments may be shown as answers.
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?

                    MinWidth="400" MaxWidth="900" 
                    AutoGenerateColumns="false" ScrollMode="RealTime" 
                    <telerikData:SortDescriptor Member="Rank" SortDirection="Ascending" /> 
                        <TextBlock Foreground="Green" Text="" Loaded="RadGrid8020_TextBlock_Loaded"/>  
                    <telerikGridView:GridViewDataColumn DataMemberBinding="{Binding Rank}" Header="Rank" IsFilterable="false" IsSortable="true">  
                                <StackPanel Orientation="Horizontal">  

                                    <!--HERE IS THE IMAGE!!!-->
                                    <Image Loaded="RadGrid8020_RankMoveImage_Loaded"/><TextBlock Text="{Binding Rank}"/>  
                    <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}" /> 
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();  
            Image img = (Image)sender;  
            img.Source = bmp;  

1 Answer, 1 is accepted

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

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

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