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

Grid View Image Column

5 Answers 975 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 27 Jun 2013, 12:00 PM
Hi!

I have a dataTable and one of its columns is a image (bitmap) column .
I've been trying to  show this images in my GridView by binding it to GridViewImageColumn but I don't get it. 

I read that GridViewImageColumn accepts byte[] and string types so I tryed to use this methods to convert the bitmaps and then put the result in other column and try to bind it to the  GridViewImageColumn: 

Public Shared Function BmpToByte(ByVal _bitmap As System.Drawing.Bitmap) As Byte()
    Dim _ms As New Global.System.IO.MemoryStream()
    _bitmap.Save(_ms, System.Drawing.Imaging.ImageFormat.Bmp)
    Dim _bmpArray As Byte()
    _bmpArray = _ms.ToArray()
    _ms.Flush()
    _ms.Dispose()
    Return _bmpArray
End Function



Public Function BitmapToString(ByVal bImage As Bitmap) As String
    Try
        Dim data As String
        Dim ms As New Global.System.IO.MemoryStream()
        bImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp)
        Dim _bmpArray As Byte()
 
        data = Convert.ToBase64String(ms.ToArray())
        Return data
    Catch ex As Exception
        Return String.Empty
    End Try
End Function


The column in my gridView is still empty.....

I've tryed this code:

<telerik:GridViewImageColumn DataMemberBinding="{Binding Logo}" Header="Logo"/>


And this:


<telerik:GridViewDataColumn DataMemberBinding="{Binding Logo}" Header="Logo">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Image Height="30" Width="30" Source="{Binding Logo}"></Image>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
</telerik:GridViewDataColumn>


I would really appreciate any help....



5 Answers, 1 is accepted

Sort by
0
Yoan
Telerik team
answered on 02 Jul 2013, 10:46 AM
Hello Daniel,

I would suggest you to check this online demo and our online documentation on how to use GridViewImageColumn. The same example is available in your local copy of WPF controls.

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Daniel
Top achievements
Rank 1
answered on 02 Jul 2013, 11:20 AM
Thanks for your reply.

I've tryed to follow this examples but I don't get it. Could you, please, show me a little example with a dataGridView binding to a datatable with a column with a bitmap?

Thank you.
0
Yoan
Telerik team
answered on 05 Jul 2013, 08:41 AM
Hello Daniel,

From your first reply I can see that  you are defining the GridViewImageColumn in XAML like so:

<telerik:GridViewImageColumn DataMemberBinding="{Binding Logo}" Header="Logo"/>

Since, you are binding to a dataTable, you can try DataMemberBinding="{Binding [Logo]}" instead.

However, I have attached an example project to demonstrate you grid with image column bound to DataTable.

I hope this helps.

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Daniel
Top achievements
Rank 1
answered on 05 Jul 2013, 10:48 AM
Thanks, after using

DataMemberBinding="{Binding 
[Logo]}"

it works!! :)

0
Yoan
Telerik team
answered on 05 Jul 2013, 11:35 AM
Hi Daniel,

Thank you for the update. I am glad to hear you have resolved the issue. 

Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Yoan
Telerik team
Daniel
Top achievements
Rank 1
Share this question
or