Picture and datagridview

  • Thread starter Screaming Eagles 101
  • Start date
S

Screaming Eagles 101

Hi,

is there an easy way to add a picture(box) to a column in a datagridview ?
My first column has a code, ex. 1, 2 or 3

According to these codes I'dd like to add a picture(box)
to my second column, just at the time when I show the data in the grid.

I don't save the pictures in the database, I only use them when I show the
data in the grid.


--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 
S

Screaming Eagles 101

Hi Cor,

tried it but I get a column with the same (red) image on each row :
probably because of this statement :
Dim dc As New TextAndImageColumn
dc.Image = My.Resources.RedImage
dgvPrikbord.Columns.Insert(0, dc)

To change the pic on other rows, this ain't working:
' change the image for the second row
DirectCast(dgvPrikbord.Item(0, 1), TextAndImageCell).Image =
My.Resources.BlueImage


--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
Cor Ligthert said:
Is this what you are searching for?

http://www.vb-tips.com/TextAndImageColumn.aspx

Cor
Screaming Eagles 101 said:
Hi,

is there an easy way to add a picture(box) to a column in a datagridview
?
My first column has a code, ex. 1, 2 or 3

According to these codes I'dd like to add a picture(box)
to my second column, just at the time when I show the data in the grid.

I don't save the pictures in the database, I only use them when I show
the data in the grid.


--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
 
S

Screaming Eagles 101

Cor Ligthert said:
Is this what you are searching for?

http://www.vb-tips.com/TextAndImageColumn.aspx

Cor
Screaming Eagles 101 said:
Hi,

is there an easy way to add a picture(box) to a column in a datagridview
?
My first column has a code, ex. 1, 2 or 3

According to these codes I'dd like to add a picture(box)
to my second column, just at the time when I show the data in the grid.

I don't save the pictures in the database, I only use them when I show
the data in the grid.


--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------

Actualy, after googling the whole afternoon and pulling hair, I managed to
put up something and it looks real simple,
no need to write hundreds of lines of code one doesn't understand if they
are only as smart as I am :-/

What I did can be done in 30 seconds :

1. I added this statement on top, this is to remove the red crosses where
you don't need an image in the imagecolumn
Private myBmp As Bitmap = New Bitmap(16, 16) 'to avoid red crosses

2. Then I added on designtime (can also be done
at runtime I guess...) a column to the grid,
of type DataGridViewImageColumn.

3. And then, to terminate, I add this routine
(I have 3 possible values in column 4 of my grid,
I add an image in column 0 (imagecolumn)
out off my resource file
according to the value in column 4)
that's it, no more, no less :
Private Sub dgvPrikbord_CellFormatting(ByVal sender As Object, ByVal e As
System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles
dgvPrikbord.CellFormatting

If e.ColumnIndex = 0 Then
If dgvPrikbord(4, e.RowIndex).Value = "INFO" Then
e.Value = My.Resources.ResEN.info
ElseIf dgvPrikbord(4, e.RowIndex).Value = "TI" Then
e.Value = My.Resources.ResEN.ti
ElseIf dgvPrikbord(4, e.RowIndex).Value = "IP" Then
e.Value = My.Resources.ResEN.ip
Else
e.Value = myBmp 'avoid red crosses
End If
End If

End Sub

--
Filip
http://www.ww2airborne.net/
Official Site of the 101st Airborne - 463rd PFA
skype: airborne463pfa-fiwi
[It's nice to be important, but it's more important to be nice!]
----------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top