Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6354761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:37:54+00:00 2026-05-24T22:37:54+00:00

I have a WPF application which has a listbox bound to an ObservableCollection which

  • 0

I have a WPF application which has a listbox bound to an ObservableCollection which retrieves it’s data from a Database. I am attempting to have the ListBox data refreshed every minute through the use of a DispatcherTimer.

Dim dispatcherTimer As DispatcherTimer = New System.Windows.Threading.DispatcherTimer
AddHandler dispatcherTimer.Tick, AddressOf getRoomMeetingDetails
dispatcherTimer.Interval = New TimeSpan(0, 2, 0)
dispatcherTimer.Start()

Which calls the getRoomMeetingDetails method as follows.

Public Sub getRoomMeetingDetails()
  If Not My.Settings.rbConn = Nothing And _
     Not gl_rmName = Nothing Then
       Dim sqlConn As New SqlConnection(My.Settings.rbConn)
       Dim sqlquery As String = "SELECT  *" & _
                                        "FROM table " & _
       Dim sqlCmd As New SqlCommand(sqlquery, sqlConn)
       sqlConn.Open()
       Dim dr As SqlDataReader
       dr = sqlCmd.ExecuteReader
       While dr.Read
         roomMeetingList.Add(New meetingDetails() With {.eMeetingId = dr.Item("dId")})
       End While
  End If
End Sub

I then have my two classes for the Collection as follows (I am very new to ObservableCollections and have tried my best to model my code off the MSDN examples, so if this isn’t the best method to use to achieve what I am trying to achieve, or can be done easier, please let me know)

Public Class MeetingList
  Inherits ObservableCollection(Of meetingDetails)
  Private Shared list As New MeetingList

  Public Shared Function getList() As MeetingList
    Return list
  End Function

  Private Sub New()
    AddItems()
  End Sub

  Public Shared Sub reset(ByVal rmName As String)
    list.ClearItems()
    list.AddItems()
  End Sub

  Private Sub AddItems()
  End Sub
End Class

Public Class meetingDetails
  Implements INotifyPropertyChanged

  Public Sub New()
  End Sub
  Public Property eID() As String
    Get
      Return _eID
    End Get
    Set(ByVal value As String)
       _eID = value
       OnPropertyChanged("eID")
    End Set
  End Property
  Private _eID As String

  Public Event PropertyChanged As PropertyChangedEventHandler _
        Implements INotifyPropertyChanged.PropertyChanged
End Class

What is happening is when the DispatcherTimer is called every minute, the ListBox data is duplicated which I believe is because the getRoomMeetingDetails method is adding all of the SQL results on every tick. How can I refresh the ListBox with only new data or data changes from the table?

I am really struggling to work out where I am going wrong and what needs to be added/removed for this to work.

If there is any details I am missing please let me know.

Matt

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:37:56+00:00Added an answer on May 24, 2026 at 10:37 pm

    Either you clear all the data in the listbox before adding them again or you do a check on the collection. I assume your eID is the primary key? the do something like this:

    if ( roomMeetingList.Where ( entry => entry.eID == dbID ).Count () == 0 ) {
        // add
    }
    

    C# code, but it shows the idea

    developerFusion’s convert made this VB:

    If roomMeetingList.Where(Function(entry) entry.eID = dbID).Count() = 0 Then
         ' Add
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a WPF application which has a main window composed from several custom
I have a very simple WPF application in which I am using data binding
I have a WPF application which has a DirectX component within it. This component
I have a WPF application which so far has been client only, but now
I have an WPF application which has a local rdlc report which show receipt
I have a WPF 3.5 MVVVM application which has a TextBlock in a ScrollViewer.
I have a WPF application which saves its data to XML files in a
In my WPF application, I have a main window (Branch.xaml) which has a button
I have a WPF/C# 4.0 App which has an Application file XAML that is:
I have a WPF application which uses a (currently) local database to act as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.