I have an intermittent error with the code below.
Basically I have a checkbox populated by the database I also manually insert "Select all".

I then use the Selected Item event to either Check or unckeck all the items if they select or unselect the row containing "Select All"
However this method occasionally causes stack overflow
on for (int x = 0; x <= y - 1; x++)

As it seems an intermittent problem is there a way to handle this?

Code:
this.chklstboxReportNames.Items.Add("Select All");
            foreach (DataRow dr in corpReportsLibraryDS.DataTable_UP_GetListOfReports.Rows)
            {
            chklstboxReportNames.Items.Add(dr["ReportName"].ToString());

            }


private void chklstboxReportNames_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            string itemvalue = chklstboxReportNames.Items[e.Index].ToString();
            if (itemvalue == "Select All")
            {
                int y = chklstboxReportNames.Items.Count;
                if (e.NewValue == CheckState.Checked)
                {
                    for (int x = 0; x <= y - 1; x++)
                    {
                        if (x > 0)
                        {
                            chklstboxReportNames.SetItemChecked(x, true);
                        }
                    }


                }
                else
                {
                    for (int x = 0; x <= y - 1; x++)
                    {
                        if (x > 0)
                        {
                            chklstboxReportNames.SetItemChecked(x, false);
                        }
                    }
                }
            }

         
        }