Click here to Skip to main content
14,331,729 members
Rate this:
Please Sign up or sign in to vote.
Hi,

I am trying to read a table from SQL containing 8 columns with values from 1 to 3, and if the value in a cell is 1, the i want the datagridview to show image 1 in the cell as a replacement for the integer value of 1, if the value is 2, then show image 2 etc.

Is there an easy solution for converting from integer to image?

Thanks

Br
Kenneth

What I have tried:

I have read the data from SQL into a dataadapter and dataset and bound that to the datagridview, not sure that is the way to go. Maybe i should replace when in the dataset, before filling the datagrid?
Posted
Updated 17-Sep-19 23:37pm
Comments
CHill60 18-Sep-19 3:58am
   
"Is there an easy solution for converting from integer to image?" No. In fact it is impossible. What you really want to do is determine which image to use from the integer reference. That is a simple look up so what is your problem?
kjohansen2000 18-Sep-19 4:32am
   
A conversion from integer to image :) if you read above that, i wrote what i intend.

My problem is to replace the cell content from an integer to an image depending on the value in the cell. I didnt write that it is in a datagridview, that i want to manipulate cells.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi kjohansen2000,

please gothrough below steps,
'implement event "DataBindingComplete" for your dataGridView. In that...
     'start a for loop for each row of grid...
          'identify your targeted cell value in the row to write if else condition...
               'if value is XX then replace value with image.
                 Dim Img As New DataGridViewImageCell
                 'Set image value
                 Img.Value = Image.FromFile("..Path of image...")
                 'Add the image cell to a row
                 DataGridView1.Rows(0).Cells.Add(Img)

here are link you can take as reference for few of above steps.
dataBind event DataGridView.DataBindingComplete Event (System.Windows.Forms) | Microsoft Docs[^]
loading image in datagrid cell displaying image in datagridviewimagecolumn in vb.net - Stack Overflow[^]

Hope that helps
Happy Coding! :)
   
Comments
Maciej Los 18-Sep-19 6:43am
   
5ed!
Aarti Meswania 18-Sep-19 6:46am
   
Thank you, Maciej Los :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100