Results 1 to 11 of 11

Thread: [RESOLVED] DataGridView visible interference while scrolling

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Resolved [RESOLVED] DataGridView visible interference while scrolling

    I have a datagridview on a form which displays data. The datagridview scrolls both horizontally and vertically. It works but when I scroll to the right and then scroll up and down you can see flashes of gray on the view during the scroll. Once you stop scrolling the gray disappears. This affects approximately the right third of the dgv. If I don't scroll to the right and scroll up and down I don't see these artifacts. What can I do to get rid of these flashes of gray while vertical scrolling?

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,714

    Re: DataGridView visible interference while scrolling

    Hello,

    Are there any events you have the DataGridView subscribed to e.g. CellFormatting etc.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: DataGridView visible interference while scrolling

    There is a cellclick event.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: DataGridView visible interference while scrolling

    Removing the cellclick handler made no difference.

    The part of the dgv where the artifacts appear is on the right side and corresponds, almost, to the part which cannot be seen when the dgv is scrolled fully left.

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridView visible interference while scrolling

    Try subclassing your DGV and making it DoubleBuffered:

    Code:
    Public Class DoubleBufferedDataGridView
        Inherits DataGridView
    
        Public Sub New()
            Me.DoubleBuffered = True
        End Sub
    
    End Class

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: DataGridView visible interference while scrolling

    Thanks. I've never heard of a double-buffered datagridview. My dgv is created with code. Simply adding "DoubleBuffered" to the declaration did not work. What to do?

    Code:
    Dim ReportDataGridView as DataGridView
    Code:
    ReportDataGridView = New DataGridView
    ReportDataGridView.Name = "Stock Items Report"
    ReportDataGridView.Left = 14
    ReportDataGridView.Top = 82
    ReportDataGridView.Height = 520
    ReportDataGridView.Width = 956
    ReportDataGridView.BorderStyle = BorderStyle.None
    ReportDataGridView.RowsDefaultCellStyle.SelectionBackColor = Color.DarkKhaki
    ReportDataGridView.RowsDefaultCellStyle.SelectionForeColor = Color.Black
    ReportDataGridView.RowsDefaultCellStyle.BackColor = Color.LightYellow
    ReportDataGridView.RowsDefaultCellStyle.Font = New Font("Microsoft Sans Serif", 12)
    ReportDataGridView.AlternatingRowsDefaultCellStyle.BackColor = Color.PaleGoldenrod
    ReportDataGridView.ColumnHeadersDefaultCellStyle.Font = New Font("Microsoft Sans Serif", 11)
    ReportDataGridView.ColumnHeadersHeight = 28
    ReportDataGridView.AllowUserToAddRows = False
    ReportDataGridView.AllowUserToDeleteRows = False
    AddHandler ReportDataGridView.CellClick, AddressOf ReportDataGridView_CellClick
    
    Controls.Add(ReportDataGridView)

  7. #7
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridView visible interference while scrolling

    Add the DoubleBufferedDataGridView class to your project (from post #5), then:

    Code:
    Dim ReportDataGridView as DoubleBufferedDataGridView
    Code:
    ReportDataGridView = New DoubleBufferedDataGridView
    It will automatically be doublebuffered with no further code, and the dgv will be as a standard dgv except double buffering, which will hopefully improve the graphics performance...

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: DataGridView visible interference while scrolling

    When I change Dim ReportDataGridView as DataGridView to Dim ReportDataGridView as DoubleBufferedDataGridView I get the message "Type DoubleBufferedDataGridView is not defined". I'm using Visual Basic 2010 Express.

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: DataGridView visible interference while scrolling

    Did you add a class, name it DoubleBufferedDataGridView and paste the code from post #5 into the class as i told you to do?
    DoubleBufferedDataGridView is a custom control. It is necessary because that is the only way to apply double buffering to a dgv.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    South Charleston, WV, USA
    Posts
    607

    Re: DataGridView visible interference while scrolling

    It's working beautiflly! Thank you. You rate a 10.

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,424

    Re: [RESOLVED] DataGridView visible interference while scrolling

    Glad i was able to help. That was my best shot. If that hadn't worked it might've been unsolveable.

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