DataGridView and ImageList

missshhhh

Member
Joined
Nov 26, 2006
Messages
13
Programming Experience
3-5
Hi, i have a DataGridView and I want to have a column (named "Image") that will display an image. But not all of the cells in the column will have an image, only those that are important which will be based on my If...Else statement. What I know is that if i set the whole column will display an image, then a box with a red X mark will be displayed if no icon is associated with it.

Also, I have an ImageList which contains all my images. Unfortunately, when I do this

DataGridView.Rows(0).Cells("Image") = iconsImageList.Images(0) it does not work, it shows the box with a red X mark. Why is this happening?
 
This code answers both questions:
VB.NET:
[COLOR=blue]Column1[/COLOR].DefaultCellStyle.NullValue = Nothing
 
DataGridView1.Rows(0).Cells("[COLOR=blue]Column1[/COLOR]").[COLOR=darkgreen]Value[/COLOR] = iconsImageList.Images(0)
 
ImageList problem

The first one did work but the second did not. I am not sure if I am doing something wrong with the ImageList. But in the Images Collection Editor, I have (0) image.gif so I am sure that iconsImageList.Images(0) should work. The problem is it is not displaying the image. Wonder why?
 
I tried doing this - Column1.Image = iconsImageList.Images(0) and it worked. How come it won't work in - DataGridView1.Rows(0).Cells("Column1").Value = iconsImageList.Images(0)
 
Image in DataGrid

I have a DataGridView1 and I have 5 columns. I want the first column to display an image but the appearance of the image will be based on my If Else statement. I also have an ImageList which contains 1 gif file. So I think that the code iconsImageList.Images(0) should display the image.

The problem is this works:
VB.NET:
Column1.Image = iconsImageList.Images(0)
while not this:
VB.NET:
DataGridView1.Rows(0).Cells("Column1").Value = iconsImageList.Images(0)
Is anything wrong with my code? Thanks.:)
 
Last edited by a moderator:
Back
Top