I use Visual studio 8.0

My question is, if a row is clicked in datagridview I want that image appears in the headercell of the row

If I use following code goes well:
DataGridView1.Rows(i).HeaderCell.Value = "selected"
Then the text "selected" appear in the headercell of the row that is selected.

Now I want instead of a text that an image appears.

I've tried the following code, but that does not work!

DataGridView1.Rows(i).HeaderCell.Value = System.Drawing.Image.FromFile("c:\image\oke.png")

If anyone knows the answer, please respond !

thanks,

André

Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim i As Integer
        i = DataGridView1.CurrentRow.Index
        DataGridView1.Rows(i).Selected = True
        DataGridView1.AutoResizeRowHeadersWidth(DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders)
        DataGridView1.Rows(i).HeaderCell.Value = System.Drawing.Image.FromFile("c:\image\oke.png")
 End Sub

Recommended Answers

All 2 Replies

Handle cellpainting event of datagridview.

Private Sub DataGridView1_CellPainting(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
        If e.ColumnIndex < 0 AndAlso e.RowIndex >= 0 Then
            e.PaintBackground(e.ClipBounds, True)
            e.Graphics.DrawImage(Image.FromFile("file.png"), e.CellBounds)
            e.Handled = True
        End If
    End Sub

Now all headercells gets a image.
it is also possible that only the selected row gets a image in headercell and all other headercell are clean.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.