We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Display Image from file based on value of a property

I have a database table that has a property with the string value of an image file on the system (i.e. "C:\Users\George\Pictures\2013 11-11-13\IMG_20130607_215118_134.jpg". I want to display the image in a cell within the grid. I am new to Syncfusion controls and can not figure out how to get this to work. 

10 Replies

MG Mohanraj Gunasekaran Syncfusion Team December 27, 2016 10:39 AM UTC

Hi George, 

Thanks for using Syncfusion products. 

We have already provided the KB regarding image loading in grid cell, 

Note: In attached sample, we have created the ImageList and added the Image using following code. You can replace your image file location instead of the below highlighted location to load your image in the grid cell. 
 
Code snippet: 
ImageList image = new ImageList(); 
image.Images.Add(Image.FromFile(@"\..\..\Images\logo1.jpg")); 

If you provide the image path as a cell value, you can get this value using e.Style.CellValue in QueryCellStyleInfo event. Then you can get the image from provided path. Please refer the below code snippet,  
Code snippet: 
this.gridGroupingControl1.QueryCellStyleInfo += gridGroupingControl1_QueryCellStyleInfo; 
ImageList image = new ImageList(); 
void gridGroupingControl1_QueryCellStyleInfo(object sender, GridTableCellStyleInfoEventArgs e) 
{ 
   if (e.TableCellIdentity != null && e.TableCellIdentity.Column != null 
    && e.TableCellIdentity.Column.Name == "ImageColumn" && e.TableCellIdentity.TableCellType != GridTableCellType.ColumnHeaderCell)     
    { 
        e.Style.CellType = GridCellTypeName.Image; 
        //image collection is stored in this list 
        if (File.Exists(e.Style.CellValue.ToString())) 
        { 
            image.Images.Clear(); 
            image.Images.Add(Image.FromFile(e.Style.CellValue.ToString())); 
        } 
        e.Style.ImageList = image; 
        //index of the image to be added. 
        e.Style.ImageIndex = 0; 
    } 
} 

The below documentation link can be helpful to use our GridGroupingControl, 

Regards, 
Mohanraj G. 



GB George Busby December 30, 2016 04:57 PM UTC

I updated my code ( using VB) but when I execute the code I get this error message. I stepped through the code in debug mode and this error message appeared after successfully walking through all of the code.

Symbol File not loaded
No symbol file loaded for Syncfusion.Grid.Windows.dll
Module Information 
Version: 14.3460.0.49
Original Location: D:\Visual Studio 2015\Projects\PhotoDirectory2016\PhotoDirectory2015\bin\Debug\Syncfusion.Grid.Windows.dll

Symbol load information
Binary was not built with debug information


GB George Busby December 30, 2016 10:29 PM UTC

I installed version 14.4.0.15 and Webroot detected a threat during the install

Malware Group:
W32.Malware.Gen

file: startdexplorecrl.exe


MG Mohanraj Gunasekaran Syncfusion Team January 2, 2017 12:39 PM UTC

Hi George, 

Please find your responses in below table, 
I installed version 14.4.0.15 and Webroot detected a threat during the install 
 
Malware Group: 
W32.Malware.Gen 
 
file: startdexplorecrl.exe 


We have updated the response through your incident. So please login your account and find the response in your created incident. 
Symbol File not loaded 
No symbol file loaded for Syncfusion.Grid.Windows.dll 

We are not able to reproduce your scenario at our end. We suspect symbol file were loading from your local machine please find the response in below table 

Solution 1: 
The reported scenario can be resolved by unload the solution file and delete the bin, obj file for the solution. Now reload and build the solution. 

Solution 2: 
In order to resolve the issue, please follow the below steps, 
1.       Tools -> Options -> Debugging -> Symbols and pressed Empty Symbol Cache in your visual studio. 
2.       Click on ok button. 






If you are still facing this issue, please provide the sample or modify the below attached sample to reproduce your scenario. It will helpful to provide the solution at the earliest. 

Sample link: GridGroupingControl 


Regards, 
Mohanraj G. 
 



GB George Busby January 5, 2017 02:25 AM UTC

I cleared the Symbol cache and now I am getting an error thread.cs not found. Also a window pops up with the message:
An unhandled exception of type 'System.NullReferenceException' occurred in Syncfusion.Grid.Windows.dll

Here is the code. It is a form  (Form4) that only has one gridgrouping control addded (gridGroupingControl1)

Public Class Form4
    Private Sub Form4_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'AmGavDirectoryDataSet.PhotoDirectoryList' table. You can move, or remove it, as needed.
        Me.PhotoDirectoryListTableAdapter.Fill(Me.AmGavDirectoryDataSet.PhotoDirectoryList)
        AddHandler Me.GridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo
    End Sub
    Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs)
        If e.TableCellIdentity IsNot Nothing Then
            If e.TableCellIdentity.Column IsNot Nothing Then
                If e.TableCellIdentity.Column.Name = "Photo" And e.TableCellIdentity.TableCellType <> GridTableCellType.ColumnHeaderCell Then
                    e.Style.CellType = GridCellTypeName.Image
                    Dim Myimage As New ImageList
                    'image collection is stored in this list
                    If (File.Exists(e.Style.CellValue.ToString())) Then
                        Myimage.Images.Clear()
                        Myimage.Images.Add(Image.FromFile(e.Style.CellValue.ToString()))
                        e.Style.ImageList = Myimage
                        'index of the image to be added. 
                        e.Style.ImageIndex = 0
                    End If
                End If
            End If
        End If
    End Sub

End Class


MG Mohanraj Gunasekaran Syncfusion Team January 5, 2017 11:04 AM UTC

Hi George, 

Sorry for the inconvenience caused. 

We have tried to reproduce your scenario, but we are not able to reproduce your scenario at our end. Here we have provided the sample as like your customization. In our sample, we have bound the BindingList with GridGroupingControl. In this BindingList, we have used the Picture property to save the image path and load the image from the path for the Picture column using QueryCellStyleInfo event. Please refer the below code snippet and refer the below attached sample.  

Code snippet 
' DataSource 
Dim dataSource As New DataCollection() 
Dim rand As New Random() 
Dim r As Integer = rand.Next(100) 
For i As Integer = 0 To 5 
     dataSource.Add(New Data(r.ToString(), "Category" & r.ToString(), "Desc" & r.ToString(), r.ToString() & "Data", FindFile("\Images\image" & (r Mod 4).ToString() & ".jpg"))) 
     r = rand.Next(100) 
Next i 
 
AddHandler Me.gridGroupingControl1.QueryCellStyleInfo, AddressOf gridGroupingControl1_QueryCellStyleInfo 
 
Private Sub gridGroupingControl1_QueryCellStyleInfo(ByVal sender As Object, ByVal e As Syncfusion.Windows.Forms.Grid.Grouping.GridTableCellStyleInfoEventArgs) 
If e.TableCellIdentity IsNot Nothing Then 
      If e.TableCellIdentity.Column IsNot Nothing Then 
         If e.TableCellIdentity.Column.Name = "Picture" And e.TableCellIdentity.TableCellType <> GridTableCellType.ColumnHeaderCell Then 
              e.Style.CellType = GridCellTypeName.Image 
              Dim Myimage As New ImageList 
              'image collection is stored in this list 
               Dim path As String = e.Style.CellValue.ToString() 
               If (Not String.IsNullOrEmpty(e.Style.CellValue.ToString()) And File.Exists(path)) Then 
                    Myimage.Images.Clear() 
                    Dim img As Image = Image.FromFile(path) 
                    Myimage.Images.Add(img) 
                    e.Style.ImageList = Myimage 
                    'index of the image to be added.  
                    e.Style.ImageIndex = 0 
               End If 
           End If 
       End If 
   End If 
End Sub 

Sample link: GridGroupingControl 

If we missed anything in our sample, please modify the sample or provide the sample to reproduce your scenario. It will be helpful to provide the solution at the earliest. 

Regards, 
Mohanraj G 



GB George Busby January 7, 2017 03:27 AM UTC

I uninstalled Syncfusion and removed all references to it from my vb project then reinstalled syncfusion Windows Forms. I then  replaced my code with your sample and walked through the code in debug. Once I passed the line
 If e.TableCellIdentity.Column.Name = "Picture" And e.TableCellIdentity.TableCellType <> GridTableCellType.ColumnHeaderCell Then

I received the following error
Operators.vb not Found


MG Mohanraj Gunasekaran Syncfusion Team January 9, 2017 12:43 PM UTC

Hi George, 

Thanks for your update. 

We could understand your reported scenario. But unfortunately we are not able to reproduce your scenario in our sample. Can you please conform whether the issue is reproduced in our provided sample or only in your application? 

Note: 
If this issue is occurring only in your sample, please follow the below steps to resolve this issue, 

·         If the project files is copied from your machine to another machine with (.suo) file. Delete that (.suo) file then clean and build the solution. 
·         Please ensure the below configurations are enabled in your machine, 
o   Tools>Options>Debugging>General and checked the Enable Just My Code checkbox so that the debugger is only debugging by your code. 
o   Tools>Options>Debugging>General and then click the checkbox next to Step Over Properties And Operators (Managed Only). 

If the reported issue still persists, please provide your sample. It would be more helpful for us to provide solution at the earliest. 

Regards, 
Mohanraj G. 



GB George Busby January 22, 2017 07:16 PM UTC

The  Tools>Options>Debugging>General and checked the Enable Just My Code fixed the issue. 


MG Mohanraj Gunasekaran Syncfusion Team January 23, 2017 05:03 AM UTC

Hi George,  
 
Thanks for your update.  

We are glad to know that your reported problem has resolved. Please let us know if you have any further assistance. 

Regards, 
Mohanraj G.  


Loader.
Live Chat Icon For mobile
Up arrow icon