I have error when I press DataGridView's header

Posted on 2008-11-09
Last Modified: 2012-05-05
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

Question by:SystemSys
    LVL 7

    Expert Comment

    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.

    Author Comment

    I read the images from the resource

    genderImageCell.Value = My.Resources.email2

    Open in new window


    Accepted Solution


    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

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now