ListView Refresh

stevecking

Active member
Joined
Dec 27, 2006
Messages
32
Programming Experience
5-10
I'm building an application which uses a main form with a listview control. The listview control displays information concerning each record loaded for that Part Number. Adding a record causes a popup form to be displayed. After the user enters the record data and saves the record, I want the listview on the main form to be updated with the information. When the record information is originally loaded I use a reader object and add ListViewItems to the listview. This works very well but when I attempt to add a new ListViewItem from the popup form, effectively appending record data to the listview, it is not displayed even though I get no errors. Previously I attempted to trigger the load procedure remotely and again got no errors but no displayed data. How could I update the listview remotely and have it display the new data? Thanks in advance for your help.


VB.NET:
        Try
            If FormIsOpen("frmPpr") Then
                Dim ListItem = New ListViewItem(PprNbr)
                ListItem.SubItems.Add(PN)
                ListItem.Tag = ID
                ListItem.SubItems.Add(PprNbr)
                frmPpr.pprListView.Items.Add(ListItem)
                frmPpr.pprListView.Refresh()
            End If
        Catch ex As Exception
            Message.AppMessageBox(ex.Message, "frmPprAdd_AppendPprItem")
        End Try
 
Last edited by a moderator:
Do you have correct reference to "frmPpr"? If not this code will address the default instance of "frmPpr" while you're actually using another instance.
 
JohnH

I got my application working marvelously. After struggling with trying to implement it remotely from frmPprAdd PopUp, I gave up and implemented the design using events.

Main Form:
VB.NET:
Dim WithEvents ofrmPprAdd As New frmPprAdd
Private Sub ofrmPprAdd_PprAddComplete(ByVal PprNbr As String, ByVal PN As String, ByVal ID As Integer) Handles ofrmPprAdd.PprAddComplete
        Try
            Dim ListItem = New ListViewItem(PprNbr)
            ListItem.SubItems.Add(PN)
            ListItem.Tag = ID
            ListItem.SubItems.Add(PprNbr)
            Me.pprListView.BeginUpdate()
            Me.pprListView.Items.Add(ListItem)
            Me.pprListView.Refresh()
            Me.pprListView.EndUpdate()
            ' Parses info from the status bar and updates the number of PPRs
            ChangeNumberOfPprs(1)
        Catch ex As Exception
            Message.AppMessageBox(ex.Message, "frmPprAdd_AppendPprItem")
        End Try
    End Sub
PopUp form frmPprAdd:
VB.NET:
    Public Event PprAddComplete(ByVal PprNbr As String, ByVal PN As String, ByVal ID As Integer)

And at the appropriate place in the frmPprAdd I simply did a RaiseEvent PprAddComplete(strPprNbr, strPN, ID). The same code I was using remotely from frmPprAdd works just fine from the main form by catching the event.

Steve
 
Last edited by a moderator:
Back
Top