By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,946 Members | 1,676 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,946 IT Pros & Developers. It's quick & easy.

Picture and datagridview

P: n/a
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!]
----------------------------------------------------------------
Sep 27 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Is this what you are searching for?

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

Cor
" Screaming Eagles 101" <se*********@online.pleaseschreef in bericht
news:46***********************@news.skynet.be...
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!]
----------------------------------------------------------------

Sep 27 '07 #2

P: n/a
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[MVP]" <no************@planet.nlschreef in bericht
news:31**********************************@microsof t.com...
Is this what you are searching for?

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

Cor
" Screaming Eagles 101" <se*********@online.pleaseschreef in bericht
news:46***********************@news.skynet.be...
>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!]
----------------------------------------------------------------


Sep 28 '07 #3

P: n/a
"Cor Ligthert[MVP]" <no************@planet.nlschreef in bericht
news:31**********************************@microsof t.com...
Is this what you are searching for?

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

Cor
" Screaming Eagles 101" <se*********@online.pleaseschreef in bericht
news:46***********************@news.skynet.be...
>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.DataGridViewCellFormattingEve ntArgs) 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!]
----------------------------------------------------------------


Sep 28 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.