how hide slow visual updates to bound listbox

In the code attached there is a brief delay in refreshing the listbox contents.  During the time between the datasource being assigned and the display member and value member being assigned, the listbox displays the class names to the user.   I've tried to Hide and Show the listbox in that time, but my perception is the user would find that even more annoying.   How can I prevent the listbox from displaying the name of the class to the user?  (The listbox is bound to a bindingsource which is in turn bound to a datasouce of a list of the class.)

Public Sub MoveSelection(ByVal strdirection As String)

        Dim ndx As Integer = 0
        Dim pfc As PageFileClass = Nothing
        pfc = frm.ListBoxPageFiles.SelectedItem
        Dim fc As HPFFAFormClass = Nothing
        Dim cnt As Integer = 0
        Dim newindex As Integer = 0
        Try

            If strdirection.ToUpper = "UP" Then
                If pfc Is Nothing Then Return

                ndx = frm.ListBoxPageFiles.Items.IndexOf(pfc)


                If ndx = 0 Then
                    Return
                End If

                pg_bs.RemoveAt(ndx)
                pg_bs.Insert(ndx - 1, pfc)

                newindex = ndx - 1

            ElseIf strdirection.ToUpper = "DOWN" Then

                If pfc Is Nothing Then Return

                ndx = frm.ListBoxPageFiles.Items.IndexOf(pfc)

                If ndx = frm.ListBoxPageFiles.Items.Count - 1 Then
                    Return
                End If

                If ndx = -1 Then
                    Return
                End If
                pg_bs.RemoveAt(ndx)
                pg_bs.Insert(ndx + 1, pfc)
                newindex = ndx + 1


            End If

            frm.ListBoxPageFiles.DataSource = Nothing
            frm.ListBoxPageFiles.DataSource = pg_bs
            frm.ListBoxPageFiles.DisplayMember = "PageName"
            frm.ListBoxPageFiles.ValueMember = "Pageno"
            frm.ListBoxPageFiles.SelectedIndex = newindex

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, HPFMain.TitleBar)
        End Try

    End Sub

Open in new window

codefingerAsked:
Who is Participating?
 
CodeCruiserCommented:
Change the sequence from

            frm.ListBoxPageFiles.DataSource = Nothing
            frm.ListBoxPageFiles.DataSource = pg_bs
            frm.ListBoxPageFiles.DisplayMember = "PageName"
            frm.ListBoxPageFiles.ValueMember = "Pageno"


to

            frm.ListBoxPageFiles.DataSource = Nothing
            frm.ListBoxPageFiles.DisplayMember = "PageName"
            frm.ListBoxPageFiles.ValueMember = "Pageno"
            frm.ListBoxPageFiles.DataSource = pg_bs
0
 
codefingerAuthor Commented:
Much better!  Thanks!
0
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.

All Courses

From novice to tech pro — start learning today.