Question Stack overflow problem with DataGridView

PeterF

New member
Joined
Jul 16, 2008
Messages
4
Programming Experience
10+
G'day, I wonder if anyone can help me with this problem

I have a datagridview in which the user can select multiple items. I want to be able to toggle between displaying just selected items and all items depending on the value of a checkbox. To do this I used the following code.

VB.NET:
Private Sub chbSelectedOnly_CheckStateChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chbSelectedOnly.CheckStateChanged
        Dim i As Integer
        Try
            dgUnLinkedAppeals.SuspendLayout()
            For i = 0 To dgUnLinkedAppeals.RowCount - 1
                If Not dgUnLinkedAppeals.Rows(i).Selected() Then
                    dgUnLinkedAppeals.Rows(i).Visible = Not chbSelectedOnly.Checked()
                End If
            Next
        Catch ex As Exception
            ErrMsg(ex.ToString)
        Finally
            dgUnLinkedAppeals.ResumeLayout()
        End Try
    End Sub

However this produced a stack overflow after several hundred times through the loop. Breaking prior to the stack overflow I checked the call stack, but it showed only [External Code] and chbSelectedOnly_CheckStateChanged()

Can anyone advise why this might be happening?

Thanks
 
Checked triggers CheckStateChanged event

Just in case anyone comes across this post. Yes, the answer is glaringly obvious. Calling the .Checked() property triggers the CheckStateChanged event
 
Back
Top