dcsimg
Results 1 to 8 of 8

Thread: ScreenUpdating

  1. #1

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    ScreenUpdating

    Is there something like VBA's ScreenUpdating=Off in VB.Net? I mean, I want to manage the underlying data and wish it would not reflect on the screen until the end.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,886

    Re: ScreenUpdating

    There may well be, but it depends on exactly what you're doing.

  3. #3

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: ScreenUpdating

    I have a form with textboxes for the main dataTable with two dataGridViews binded to two child tables.
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  4. #4
    PowerPoster i00's Avatar
    Join Date
    Mar 2002
    Location
    1/2 way accross the galaxy.. and then some
    Posts
    2,347

    Re: ScreenUpdating

    the only thing i can think of is setwindowsupdate api

    Kris

  5. #5

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: ScreenUpdating

    what is that?
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

  6. #6
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Re: ScreenUpdating

    Code:
        Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal winHandle As IntPtr, ByVal wMsg As Int32, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Int32
        Private Const WM_SETREDRAW As Integer = &HB
        Public Shared Sub LockControl(ByVal control As Control, Optional ByVal lock As Boolean = True)
            SendMessage(control.Handle, WM_SETREDRAW, lock = False, 0)
        End Sub
        Public Shared Sub UnlockControl(ByVal control As Control)
            LockControl(control, False)
            control.Invalidate()
        End Sub
    Code:
    'on load add this:
    LockControl(Me)
    
    'on shown add this:
    UnlockControl(Me)
    (May need to change the SendMessage declaration, not sure if it works on x64 this way)

    Here ya go.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,886

    Re: ScreenUpdating

    If you bind your data to a BindingSource and then bind that to the controls, you should be able to set RaiseListChangedEvents to False and then call SuspendingBinding. You'd then set the property back to True and call ResumeBinding when you're done. I've never tried it but I think that it should work.

  8. #8

    Thread Starter
    PowerPoster kaliman79912's Avatar
    Join Date
    Jan 2009
    Location
    Ciudad Juarez, Chihuahua. Mexico
    Posts
    2,593

    Re: ScreenUpdating

    This is an Exam System, the form in question is where the exams are entered into it. The header, with the textboxes is the details of the exam: name, area, level, subject, etc. The first DGV is for the questions, each exam has a variable number of questions. Up to this point there is no problem as it acts as any relational form kind of like an invoice or the like. But the second DGV is for the Answers, and it has to change depending on what question is selected in the first DGV, this is where the problems begin, as I have an event handler for each time the selected row changes in the questions DGV to fetch the appropriate Answers, but then, when I copy an exam or when some changes are made and even on form load this event is triggered many times, and in some cases, when a new exam is being added (only during a copy from an existing exam) the question is null and the program crashes. I have handled this checking for the ID value vs Null but the procedure is still triggered many times each iteration (for each question) and that takes time.

    All that said, I have used RaiseListChangedEvents = false (thanks to an old thread answered by jmc) and it solved some of the cases but not all. SuspendBinding sounds like it may work, will try it tonight.

    Thank you all
    More important than the will to succeed, is the will to prepare for success.

    Please rate the posts, your comments are the fuel to keep helping people

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width