CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2009
    Posts
    177

    Datagridview change image

    I have the following code :

    Code:
    
    
        Private Sub dgPackage_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgPackage.CellFormatting
            Try   
                SetRowBackColor(Me.dgPackage, "colPkgAdjustmentRange")
              
                If Me.dgPackage.Rows.Count > 0 Then
                    For intRow = 0 To dgPackage.Rows.Count - 1
                        If dgPackage.Rows(intRow).Cells("colPkgAdjustmentRange").Value = "AFTER" Then
                            If dgPackage.Rows(intRow).Cells("colPkgApprovalStatus").Value.ToString.Contains("PENDING") Then
                                Dim imageColumn As DataGridViewImageCell = CType(dgPackage.Rows(intRow).Cells("colPkgImage"), DataGridViewImageCell)
                                imageColumn.Value = My.Resources.ResourceFile.Pending
                            End If
                        End If
                    Next
                End If
            Catch ex As Exception
                Throw
            End Try
        End Sub

    The problem is the datagridview will keep on blinking and it will not continue the next action...

  2. #2
    Join Date
    Jun 2005
    Location
    JHB South Africa
    Posts
    3,772

    Re: Datagridview change image

    Looks like the problem you have here is recursive code...

    something in the code is re-triggering the Cell formatting.. and I suspect that it could be
    Code:
                                Dim imageColumn As DataGridViewImageCell = CType(dgPackage.Rows(intRow).Cells("colPkgImage"), DataGridViewImageCell)
                                imageColumn.Value = My.Resources.ResourceFile.Pending
    Comment out these lines and check what happens...
    If this stops the problem, what you have to do is first add some checking to see if the cell has not been set beforehand, else find another event to place the code in, like RowsAdded or RowValidating...
    Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
    WPF Articles : 3D Animation 1 , 2 , 3
    Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
    Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
    All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured