0

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
2
Contributors
2
Replies
5
Views
6 Years
Discussion Span
Last Post by dre-logics
0

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
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.