Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

vb.net datagrid - How to set a background image for a cell

Avatar of PaulEll
PaulEll asked on
Visual Basic ClassicVisual Basic.NET
9 Comments1 Solution3399 ViewsLast Modified:
Hi there,

I am using VB.net and I am trying to add a background image to a datagrid cell.
This is either impossible or I have missed something very simple.
Hopefully somebody here can point me in the right direction.

The code below just sets the background colour depending on a value.

What I really want to be able to do is

.Columns(0).DefaultCellStyle.BackImage = MyImage.

Has any one done this ? Can you point me in the right direction.

I can only use VB.net for the solution.

Thanks
Paul



DataGrid1.DataSource = MyCalendarTable

        With DataGrid1
            .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            .RowHeadersVisible = False

            If MyDay1 = "Sun" Then
                .Columns(0).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            If MyDay2 = "Sun" Then
                .Columns(1).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            If MyDay3 = "Sun" Then
                .Columns(2).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            If MyDay4 = "Sun" Then
                .Columns(3).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            If MyDay5 = "Sun" Then
                .Columns(4).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            If MyDay6 = "Sun" Then
                .Columns(5).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            If MyDay7 = "Sun" Then
                .Columns(6).DefaultCellStyle.BackColor = Color.Gainsboro
            End If

            .Columns(3).DefaultCellStyle.BackColor = Color.LightCyan
        End With