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

GridView will not display an image

4 Answers 475 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 14 Oct 2010, 02:41 PM
I've spent hours on this and have tried many ways.  For the life of me I cannot make a GridView display any image.

I have a class called Employee.  I then have a List<Employee> which is bound to the GridView ItemsSource.  All bindings are working just fine.  The first column in the grid is a GridViewImageColumn.  I have never had it display an image.  I've set my Employee.Photo property to be a Bitmap, and Image, a BitmapImage, and I've used System.Windows.Drawing as well as System.Windows.Controls, and System.Media.Imaging (I think that was the 3rd one).

When loading the image for the employee, here's the latest code I've tried:

BitmapImage bmp = new BitmapImage();
bmp.BeginInit();
bmp.UriSource = new Uri(@"FULL PATH TO THE FILE"UriKind.Absolute);
bmp.EndInit(); Employee.Picture.Source = bmp; SomeImageOnTheForm.Source = bmp; // To test the successful load.

What can possibly be wrong?  The Image on the form loads the picture just fine.  The grid never does.

4 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 14 Oct 2010, 02:52 PM
Hello Paul,

I am not sure what may be wrong , but we can address this the following way.
Plese send me a few of the images you are using , and I wil prepare a small project with RadGridView  that dislpays them  in a column
I need the images in case there is a problem with the image format itself.

Let me know if there are any specific additional requirements so I can take care of them while preparing the sample.
Additionaly , please confirm that you are using the 2010.2.924 version of the Telerik dlls, so I can make the sample with the same.

Regards,
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
Paul
Top achievements
Rank 1
answered on 14 Oct 2010, 03:03 PM
I've tried quite a few images.  Most were just found using Google Images and searching for 'headshots' since they're supposed to be employees.  I attached one example. 
 
The code to load the image was in the post.  Below is the XAML for the grid as well as a snippet of code from my ojbject class.  The DataContext and ItemsSource are set in code-behind.  The other fields all display fine.

                <telerik:RadGridView Opacity="0.80" Grid.RowSpan="2" Name="gridMain" AutoGenerateColumns="False" 
                                    CanUserDeleteRows="False" CanUserInsertRows="False" EditTriggers="None" 
                                    IsFilteringAllowed="False" IsReadOnly="True" ShowGroupPanel="False"
                                    ScrollMode="RealTime" GridLinesVisibility="None" 
                                    ShowColumnHeaders="False" >

                    <telerik:RadGridView.Columns>
                        <telerik:GridViewToggleRowDetailsColumn />
                        <telerik:GridViewImageColumn Header="{StaticResource Photo}" DataMemberBinding="{Binding Picture}" ImageHeight="40" ImageWidth="40" />
                        <telerik:GridViewDataColumn Header="{StaticResource Inits}" DataMemberBinding="{Binding Inits}" />
                        <telerik:GridViewDataColumn Header="{StaticResource Name}" DataMemberBinding="{Binding EmpName}" />
                        <telerik:GridViewDataColumn Header="{StaticResource Last_Clock_Time}" DataMemberBinding="{Binding DisplayTime}" />
                        <telerik:GridViewDataColumn Header="{StaticResource Information}" DataMemberBinding="{Binding ROCategory}" />
                    </telerik:RadGridView.Columns>
                </telerik:RadGridView>
   class clsEmployee
   {
      // There's of course a lot of other fields...
      public Image Picture { getset; }
      
      public clsEmployee()
      {
         Picture = new Image();
      }
0
Accepted
Pavel Pavlov
Telerik team
answered on 14 Oct 2010, 03:28 PM
Hello Paul,

I have tried your code  and found a small modification in the binding makes it work :

<telerik:GridViewImageColumn Header="test" DataMemberBinding="{Binding Picture.Source}" ImageHeight="40" ImageWidth="40" />

*changed the path to Picture.Source.

As promissed , I am attaching the test app as well.
In case you want to test it, please change the hardcoded path in the constructor to the one on your local machine.

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
Paul
Top achievements
Rank 1
answered on 14 Oct 2010, 03:30 PM
WOW...  So simple, and I never thought to try it.  Thank you so much.  It's working perfectly.
Tags
GridView
Asked by
Paul
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Paul
Top achievements
Rank 1
Share this question
or