Image in Datagridview

How i add images in data gridview at runtime.

i am trying as below

but not getting correct output

 Plz help me
Dim x As Integer
        Dim imageColumn As System.Windows.Forms.DataGridViewImageColumn
        Dim columnCount As Integer = 0
        Do
            
            imageColumn = New System.Windows.Forms.DataGridViewImageColumn
            i = 0
            
            imageColumn.Image = ImageList1.Images.Item(i)
 
            imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
            imageColumn.Description = "default image layout"
            DataGridView1.Columns.Add(imageColumn)
            columnCount = columnCount + 1
            i = i + 1
        Loop While columnCount < 3
        DataGridView1.Refresh()

Open in new window

choubeybAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vb_jonasCommented:
If you set the image in cellformatting instead you can control the image displayed for each row & column:
    Private Sub DataGridView1_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
        If e.ColumnIndex = 1 Then
            e.Value = ImageList1.Images.Item(0)
        End If
    End Sub

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Computer101Commented:
Forced accept.

Computer101
EE Admin
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.