Image in Datagridview

Posted on 2008-01-30
Medium Priority
Last Modified: 2013-11-26
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
            imageColumn = New System.Windows.Forms.DataGridViewImageColumn
            i = 0
            imageColumn.Image = ImageList1.Images.Item(i)
            imageColumn.ImageLayout = DataGridViewImageCellLayout.Stretch
            imageColumn.Description = "default image layout"
            columnCount = columnCount + 1
            i = i + 1
        Loop While columnCount < 3

Open in new window

Question by:choubeyb
LVL 12

Accepted Solution

vb_jonas earned 2000 total points
ID: 20784574
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


Expert Comment

ID: 21288064
Forced accept.

EE Admin

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Planning to migrate your EDB file(s) to a new or an existing Outlook PST file? This video will guide you how to convert EDB file(s) to PST. Besides this, it also describes, how one can easily search any item(s) from multiple folders or mailboxes…

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question