Display Image in RadGridView using ItemsSource Bound to LinqToSQL via WCF

7 posts, 0 answers
  1. Christian Muggli
    Christian Muggli avatar
    7 posts
    Member since:
    Jul 2009

    Posted 30 Jan 2010 Link to this post

    What i have:

    A SQL table with a column DocTypeIcon of data type Image.
    I'm using LinqToSql to retrieve the data. Using WCF i ship the data to a Silverlight Application. In the Silverlight Application i have a Class (kind of mediator) to do the annotation for the fields (ColumnHeaders) like:

    [DisplayAttribute(AutoGenerateField = false)]
    public String DocId { get; set; }
    [DisplayAttribute(Name="Document Name")]
    public String DocName { get; set; }



    etc..

    The Items retrieved from the database are then added to a List<DatabaseRecords>. The list is then bound to a RadGridView.ItemsSource. All the data is displayed almost perfectly, but i don't get it to display the image...

    i tried this:

                            <telerikGridView:RadGridView x:Name="dgDocuments" HorizontalAlignment="Left" Margin="16,189,0,278">
                                <telerikGridView:RadGridView.Columns>
                                    <telerikGridView:GridViewImageColumn Header="DocTypeIcon" DataMemberBinding="{Binding DocTypeIcon}"/>
                                </telerikGridView:RadGridView.Columns>
                            </telerikGridView:RadGridView>

    help's/comments are really appreciated!

    Christian




  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Feb 2010 Link to this post

    Hi Christian,

    Can you post more info about the image type saved in this field?

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. DevCraft banner
  4. Christian Muggli
    Christian Muggli avatar
    7 posts
    Member since:
    Jul 2009

    Posted 01 Feb 2010 Link to this post

    Hi Vlad

    It's a PNG. And it comes in as

    ?dr.DocTypeIcon.GetType();
    {SomeSilverlightApp.DatabaseServiceSubscription.Binary}

    cheers, Christian


  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 01 Feb 2010 Link to this post

    Hi Christian Muggli,

    Have you checked this online example  ? I believe it is simillar to your scenario.

    All the best,
    Pavel Pavlov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Christian Muggli
    Christian Muggli avatar
    7 posts
    Member since:
    Jul 2009

    Posted 01 Feb 2010 Link to this post

    Hi Pavel

    Yes, my code is based on that example. But i hade to put some kind of 'mediator-class' between the the RadGridView.ItemsSource and the results that i get from the WCF (i do NOT use RIA) to manage the ColumnHeader and AutoGeneration of the Columns using DataAnnotations (i wrote the in my initial post, but maybe that didn't came too clear..).
    The image gets displayed correctly in the Grid as long as i don't have my mediator-class between the .ItemsSource and the results i get from the WCF.
    So the question is:
    The result i get from WCF is of type:
    {SomeSilverlightApp.DatabaseServiceSubscription.Binary} 





    When i declare the type in my Class like (is that the correct data type??):

    public Byte[] img { getset; } 

    in the XAML File i declared it like:

    <telerikGridView:GridViewImageColumn Header="img" DataMemberBinding="{Binding img.Bytes}"/>

    and i tried also the DataMemberBinding="{Binding img}"

    i always get an empty cell...

    cheers,

    Christian
  7. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 04 Feb 2010 Link to this post

    Hello Christian Muggli,


    Everything seems ok in your code. You can feed the ImageColumn with bytes array and it should work OK .  Without having the code of your project I may only guess what causes the trouble but here are some thoughts : 

    The  problem may be in the asynchronous nature of the service - the data may come a bit later when the column is already initialized .  This can be easily checked - for your mediator class please inherit and implement the INotifyPropertyChanged interface. This way  RadGridView will sense any on-the-fly changes and will update the ui (e.g. if data comes a  bit later ) .

    If this does not solve the problem I may be in help the following ways :

    1. You can open a support ticket and send me you project so I can try fix it for you. ( any content/code  will be treated as confidential).

    2. If 1. is not applicable , you may just paste me as much relevant code as possible here so I can try to resemble the problem here.

    Greetings,
    Pavel Pavlov
    the Telerik team

    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
    Follow the status of features or bugs in PITS and vote for them to affect their priority.
  8. Christian Muggli
    Christian Muggli avatar
    7 posts
    Member since:
    Jul 2009

    Posted 09 Feb 2010 Link to this post

    Hi Pavel

    Thanks for your suggestions.

    in the meanwhile, i changed my application to take the graphics out of a resource file embedded in the Silverlight Application. That's because i had and still have time-pressure releasing the product.

    Still, if i ever find time to do a sample / test solution just to know whether it would work or not i would post it here for the community.

    thanks for your time

    Christian
Back to Top
DevCraft banner