Hello,
VS 2008
I am using a bindingList that is bound to a listbox.
Howerver, everytime I modify an item in the bindingList and call the resetItem to update the list box. It fires the selectedIndexChange property. This then goes into an ever ending loop.
I have been looping through with the debugger, but can't understand why it loops.
I have tried to set the RaisedListChangedEvent to false. However, that doesn't allow the listbox to be updated. I have tried the phoneLineItem.ResetItem(currentLine)in other parts of the code. And it doesn't call the selectedIndexChanged event. This only happens in the SetRingingState sub.
I think it might difficult to predict what is happening with this code, as you will have to see it running. However, any pointers on how the right direction could lead to me solving this problem. I can't think of any reason why this should happen.
Many thanks for any suggestions,
Binding the list to the list box.
Selection Index changed event. This gets called everytime the phoneLineItem.ResetItem(currentLine) is called. That starts the loop of. ProcessCurrentState is a function in another class that calls the SetRingingState().
//The SetRingingState will go back to the selectedIndexChanged Event when the phoneLineItem.ResetItem(currentLine) is called. So it never leaves this sub.
VS 2008
I am using a bindingList that is bound to a listbox.
Howerver, everytime I modify an item in the bindingList and call the resetItem to update the list box. It fires the selectedIndexChange property. This then goes into an ever ending loop.
I have been looping through with the debugger, but can't understand why it loops.
I have tried to set the RaisedListChangedEvent to false. However, that doesn't allow the listbox to be updated. I have tried the phoneLineItem.ResetItem(currentLine)in other parts of the code. And it doesn't call the selectedIndexChanged event. This only happens in the SetRingingState sub.
I think it might difficult to predict what is happening with this code, as you will have to see it running. However, any pointers on how the right direction could lead to me solving this problem. I can't think of any reason why this should happen.
Many thanks for any suggestions,
Binding the list to the list box.
Code:
Private phoneLineItem As New BindingList(Of PhoneLine)()
Private Sub PopulatePhoneLines()
For i As Integer = 0 To 6
'Create new object for each line - initalize each line
line(i) = New PhoneLine(i, String.Empty, "Free", False, Me)
'Add object to the bindingList
phoneLineItem.Add(line(i))
Next
'Databind the list box with the BindingList
'Ensure that the datasource has been set before selecting a line from the list box.
Me.isDataSourceSet = False
Me.lstPhoneLines.DataSource = phoneLineItem
Me.lstPhoneLines.ValueMember = "CurrentLineStatus"
Me.lstPhoneLines.DisplayMember = "CurrentLineStatus"
'Set line 0 as the initial selection on startup
Me.lstPhoneLines.SelectedIndex = 0
Me.isDataSourceSet = True
End Sub
Selection Index changed event. This gets called everytime the phoneLineItem.ResetItem(currentLine) is called. That starts the loop of. ProcessCurrentState is a function in another class that calls the SetRingingState().
Code:
'Change the button setting based on the line object current state.
Private Sub lstPhoneLines_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
' MessageBox.Show(sender.GetType().ToString());
Debug.WriteLine("Selected Index Changed Event Fired")
'phoneLineItem.RaiseListChangedEvents = false;
If isDataSourceSet Then
currentLine = Me.lstPhoneLines.SelectedIndex
If currentLine > -1 Then
//Calls function in another class that calls: SetRingingState()
Me.phoneLineItem(currentLine).fsm().processCurrentState()
End If
End If
End Sub
//The SetRingingState will go back to the selectedIndexChanged Event when the phoneLineItem.ResetItem(currentLine) is called. So it never leaves this sub.
Code:
Public Sub SetRingingState()
Me.btnCallAnswer.Text = "Answer"
Me.btnEndCallReject.Text = "Reject"
Me.btnCallAnswer.Enabled = True
Me.btnEndCallReject.Enabled = True
Me.btnRedial.Enabled = False
Me.btnHoldUnhold.Enabled = False
phoneLineItem(currentLine).LineStatus = "Ringing"
phoneLineItem(currentLine).Holding = False
phoneLineItem.ResetItem(currentLine)
End Sub