|
-
Dec 15th, 2007, 01:33 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Cell Image Backgrounds
I made several images with transparent backgrounds for a column of datagridview cells, thinking I could easily set the background color of the cell to whatever I want depending on the alternating rows and highlighted row.
It's simple code and it should work (this is in the event to fill the datagridview for alternating row colors; the image is in the last column):
Code:
Dim RowCount As Integer = dgvRoster.Rows.Count - 1
Dim Cell As DataGridViewCell = dgvRoster.Rows(RowCount).Cells.Item(dgvRoster.Columns.Count - 1)
If RowCount Mod 2 = 0 Then
Cell.Style.BackColor = Color.AliceBlue
Else : Cell.Style.BackColor = Color.Azure
End If
The results are ugly; the transparent parts of the images shine right through to my coding window. My code has no effect on the images whatsoever.
I'm wondering if there's a better image format for transparentcies than the one I chose (.gif). Would jpegs or some other format yield better results or am I totally barking up the wrong tree with my approach?
Last edited by neef; Dec 16th, 2007 at 08:35 AM.
Intermediate Level Programmer Extraordinaire 
-
Dec 15th, 2007, 07:23 PM
#2
Re: [2005] Cell Image Backgrounds
you could make 2 new images, 1 with AliceBlue background + 1 with Azure background instead of transparent backgrounds.
if you want to use transparent images, .gif or .png are your only options. .jpg + .bmp don't support transparent backgrounds.
-
Dec 15th, 2007, 07:37 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] Cell Image Backgrounds
[QUOTE=.paul.]you could make 2 new images, 1 with AliceBlue background + 1 with Azure background instead of transparent backgrounds.
QUOTE]
That's what I had working before, but it got messy when I changed the colors of the rows for something seperate.
I overided the CellPainting event and took care of business there. Here's the code for anyone else with the same problem. Just make sure to set the background color in the Load event (or somewhere else before the grid cells draws themselves)
Code:
If dgvRoster.Columns("ImageColumn").Index = e.ColumnIndex Then
Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
Dim gridBrush As New SolidBrush(dgvRoster.GridColor)
Dim gridLinePen As New Pen(gridBrush)
'Erase Cell
e.Graphics.FillRectangle(backColorBrush, e.CellBounds)
' Draw the grid lines (only the right and bottom lines;
' DataGridView takes care of the others).
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
e.CellBounds.Bottom - 1)
e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
e.CellBounds.Top, e.CellBounds.Right - 1, _
e.CellBounds.Bottom)
gridLinePen.Dispose()
gridBrush.Dispose()
backColorBrush.Dispose()
End If
Code must be added to the rowenter and rowleave events as well if you want to include highlighting in addition to alternating rows.
Intermediate Level Programmer Extraordinaire 
-
Dec 16th, 2007, 01:09 AM
#4
Re: [2005] Cell Image Backgrounds
Am I missing something or are you just trying to colour alternating rows different colours? If that is the aim then the DataGridView already has a property for this: AlternatingRowsDefaultCellStyle
-
Dec 16th, 2007, 01:19 AM
#5
Re: [2005] Cell Image Backgrounds
you're missing something. the OP was having difficulty displaying transparent images in alternately coloured grid cells
-
Dec 16th, 2007, 01:37 AM
#6
Re: [2005] Cell Image Backgrounds
 Originally Posted by .paul.
you're missing something.
It's been known to happen.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|