Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Redraw in DataGridView 1

Status
Not open for further replies.

Andrzejek

Programmer
Jan 10, 2006
8,548
US

In VB 6 I was able to 'suspend' the update of the display in the grid when I populated it in code (row-by-row, not with DataSource) by something like:

[tt]
MSHFlexGrid1.Redraw = False[green]
'Do my magic here[/green]
MSHFlexGrid1.Redraw = True
[/tt]

Is there something similar to it in DataGridView?

Have fun.

---- Andy
 
Andy, probably not exactly what you're looking for, but in one of the application I wrote a while back, I had a similar issue. I ended up making my dgv not visible, and making it visible again when it was done populating.


Cheers,

Realm174
 
I don't have VS on this machine, but I believe there is a SuspendRedraw or similar property (of the Form, I think). Have a look at the form creation code, it is definitely in there. To see the creation code, select the show all files button in Solution Explorer, then under the form you will have two .vb files, one the name of the form, the other slightly different (something like formname.designer.vb) - that's the one you want - but don't change anything in it as it is recreated automatically after every change to the form design.


Hope this helps.


 
Thank you softhemc.

I found:
[tt][blue]
Me.SuspendLayout()[/blue]
Call ShowDataInGrid()[blue]
Me.ResumeLayout()[/blue]
[/tt]
That does work a little bit, not much difference, but better than nothing.

I guess re-filling the grid is as efficient as it can be.

realm174 - I did try your suggestion to make my grid not visible, and then visible again, but that would be too annoying to have the grid disappear and reappear again. Maybe if I would draw something in grid’s place for that time, like a group box or picture box, but that’s too much. :)

Have fun.

---- Andy
 
Or you can have one dummy grid as a background, then it doesn't show the on/off as much :)


Cheers,

Realm174
 
The re-filling of the grid is not that bad, I was just hoping for something to improved it. I guess I have to know when to quit to be so picky and be happy with what I've got.... :)

Have fun.

---- Andy
 
Here's a neat idea from stackoverflow by Adam Robinson using extension methods. I've adapted it for VB.Net.


First, create a Module containing the extension methods:

Code:
Imports System.Runtime.CompilerServices
Imports System.Runtime.InteropServices

Module ControlExtensionMethods

    Const WM_SETREDRAW As Integer = &HB

    <Extension()>
    Public Sub SuspendDrawing(this As Control)
        SendMessage(this.Handle, WM_SETREDRAW, 0, 0)
    End Sub

    <Extension()>
    Public Sub ResumeDrawing(this As Control)
        ResumeDrawing(this, True)
    End Sub

    <Extension()>
    Public Sub ResumeDrawing(this As Control, refresh As Boolean)
        SendMessage(this.Handle, WM_SETREDRAW, 1, 0)
        If (refresh) Then this.Refresh()
    End Sub

    <DllImport("user32.dll", SetLastError:=True)> _
    Private Function SendMessage(hwnd As IntPtr, wMsg As Integer, wParam As Integer, lParam As Integer) As Integer
    End Function

End Module

Then in your code:

Code:
Try
    MSHFlexGrid1.SuspendDrawing()
    [COLOR=#4E9A06]'Do your magic here[/color]

Finally
    MSHFlexGrid1.ResumeDrawing()
End Try
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top