tags:

views:

38

answers:

0

I am running Windows 7 and have an application that has a textbox bound to a Property in a Custom Class that Implements IEnumerable. When I call Raise Event to update the textbox it will only work the first time. However, the application works on every other OS I have tested on (XP, Vista). Also if my custom class does not implement IEnumerable it works correctly. Is this a bug? Am I doing something wrong? Any help is apperciated.

Code to reproduce (VB 2005 w/ 2.0 Framework):

A form with a textbox and a button. The Textbox is bound to the Total Property in the class. The button click should put a random integer in the textbox. Will not work on Windows 7, but will on other OS.

Public Class Form1

    Private oDS As New DataSource

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim BindingDS As New System.Windows.Forms.BindingSource(Me.components)
        BindingDS.DataSource = oDS.GetType
        BindingDS.Add(oDS)


        Me.txtTotal.DataBindings.Add("Text", BindingDS, "Total")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        oDS.UpdateTotal()
    End Sub

End Class

Public Class DataSource
    Implements IEnumerable

    Private list As New ArrayList
    Private _Total As Integer

    Public Event TotalChanged As EventHandler

    Public Sub UpdateTotal()
        RaiseEvent TotalChanged(Me, New EventArgs)
    End Sub

    Public ReadOnly Property Total() As Integer
        Get
            Return Calc()
        End Get
    End Property

    Private Function Calc() As Integer
        Dim RandomNum As New Random
        Return RandomNum.Next
    End Function

    Public Function GetEnumerator() As System.Collections.IEnumerator Implements System.Collections.IEnumerable.GetEnumerator
        Return (list.GetEnumerator)
    End Function
End Class