• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 616
  • Last Modified:

I have error when I press DataGridView's header

I have error when I press DataGridView's header to order rows

I use this Sub for Icons and  rows's color


   Private Sub SetGenderImages()
        Dim genderImageCell As DataGridViewImageCell
        Dim I As Double
        Dim Exemption_Color As Boolean

        For Each row As DataGridViewRow In Me.DataGridView1.Rows

            genderImageCell = DirectCast(row.Cells("State"), DataGridViewImageCell)
            If Exemption_Color = True Then I = I + 1

            Select Case row.Cells(5).Value
                Case "False"
                    Exemption_Color = True
                    'genderImageCell.ToolTipText = "Male"
                    Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index() + I).DefaultCellStyle.BackColor = Color.LightYellow
                    genderImageCell.Value = My.Resources.email2

                Case "True"
                    Exemption_Color = True
                    'genderImageCell.ToolTipText = "Female"
                    genderImageCell.Value = My.Resources.email_open1
                    Me.DataGridView1.Rows(Me.DataGridView1.CurrentRow.Index() + I).DefaultCellStyle.BackColor = Color.White

            End Select

        Next row
        I = 0
        Exemption_Color = False
    End Sub

Look at the Pic before I press DataGridView's header and after that

  • 2
1 Solution
I believe this link may be of use:


It leads to here:


create a resource file, then add your images to that resource file,
then read the images from the resource (which gets embedded in your assembly)
at runtime.
SystemSysAuthor Commented:
I read the images from the resource

genderImageCell.Value = My.Resources.email2

Open in new window

SystemSysAuthor Commented:

I finded my answer

Private Sub DataGridView1_RowHeaderMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridView1.RowHeaderMouseClick

Call SetGenderImages()

End Sub

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now