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




SystemSys.jpg
SystemSys2.jpg
SystemSysAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aherpsCommented:
I believe this link may be of use:

http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_22808431.html

It leads to here:

http://www.velocityreviews.com/forums/t19572-vbnetimagelist-loses-images-when-the-image-size-property-is-changed.html

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.
0
SystemSysAuthor Commented:
I read the images from the resource
         

genderImageCell.Value = My.Resources.email2

Open in new window

ddd.png
0
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
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.