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

GridViewImageColumn problem

5 Answers 451 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Imran Aliyev
Top achievements
Rank 1
Imran Aliyev asked on 23 Apr 2010, 06:54 AM

I am using Telerik RadGridView in my project. I want to show image in column.

                GridViewImageColumn col1 = new GridViewImageColumn();
                col1.Width = 100;
                col1.DataMemberBinding = new Binding("id");
                col1.Header = "PhotoByConverter";
                col1.DataMemberBinding.Converter = new ThumbnailConverter();
                grid.Columns.Add(col1);
                GridViewDataColumn col2 = new GridViewDataColumn();
                col2.Width = 100;
                col2.DataMemberBinding = new Binding("firstName");
                col2.Header = "Person name";
               
                grid.Columns.Add(col2);
                Grid.ItemsSource=DataTable; 
First column not wokrs but second works fine. I use Converter for image shown below

    public class ThumbnailConverter : IValueConverter
    {
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
                    IEnumerable<thumbNail> result = from n in thumbnails
                                        where n.personID == value.ToString()
                                        select n;
        if (result != null && result.First().thumbnail != null)
        {
            return result.First().thumbnail.file;
        }
        else
        {
            return null;
        }
    }
    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new Exception("The method or operation is not implemented.");
    }
   } 

I found by id thumbnail of person and set it like data for GridViewImageColumn. I checked with Debuger conveter works properly. I can't undesrtand why it doesn't work. Any ideas?

I use 2009 Q3 version.

My converter returns byte[] type

5 Answers, 1 is accepted

Sort by
0
Imran Aliyev
Top achievements
Rank 1
answered on 23 Apr 2010, 11:03 AM

Ä° investigate this problem and found out that with class collection everything works properly, but when I use DataTable image column doesn't work. 

0
Vlad
Telerik team
answered on 26 Apr 2010, 09:14 AM
Hi,

Do you have any invalid bindings in the Visual Studio output window?

Sincerely yours,
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
Imran Aliyev
Top achievements
Rank 1
answered on 26 Apr 2010, 09:27 AM

I create a simple project with simple code. This code not works. Name column bound fine, but Image column doesnt work

            FileStream fs = new FileStream("c:/temp/pic.jpeg", FileMode.Open, FileAccess.Read);  
            BinaryReader br = new BinaryReader(fs);  
            byte[] pic = br.ReadBytes((int)fs.Length);  
 
            DataTable dt = new DataTable();  
            dt.Columns.Add("id");  
            dt.Columns.Add("Image");  
            dt.Columns.Add("Name");  
 
            dt.Rows.Add("1", pic, "Imran");  
            dt.Rows.Add("2", pic, "Emin");  
 
            MyGrid.ItemsSource=dt; 

and my XAML:

<Window x:Class="WpfApplication3.Window1"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"  
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"  
    Title="Window1" Height="400" Width="700" Loaded="Window_Loaded"  
        xmlns:local="clr-namespace:WpfApplication3"  
        xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView">  
    <Grid>  
        <telerik:RadGridView AutoGenerateColumns="False" x:Name="MyGrid" >  
            <telerik:RadGridView.Columns>  
 
                <telerik:GridViewImageColumn Header="Image" DataMemberBinding="{Binding Image}" />  
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Width="150" Header="Name"/>  
                         
            </telerik:RadGridView.Columns>  
        </telerik:RadGridView>  
    </Grid>  
</Window> 

 Yes I have in my output windows next errors:

System.Windows.Data Error: 39 : BindingExpression path error: 'Image' property not found on 'object' ''DataRow' (HashCode=33813864)'. BindingExpression:Path=Image; DataItem='DataRow' (HashCode=33813864); target element is 'Image' (Name=''); target property is 'Source' (type 'ImageSource')

What does it mean?

0
Accepted
Vlad
Telerik team
answered on 26 Apr 2010, 09:30 AM
Hi,

You can try DataMemberBinding="{Binding [Image]}" instead.

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
Imran Aliyev
Top achievements
Rank 1
answered on 26 Apr 2010, 09:33 AM
Thank you very much Vlad. It works!!!
Tags
GridView
Asked by
Imran Aliyev
Top achievements
Rank 1
Answers by
Imran Aliyev
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or