public RerunListForm(RerunSettings criteria, Identifiable [] selectedExperiments,
                             Identifiable [] allItems, Identifiable [] criteriaSelectedItems)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            StringBuilder str;

            str = new StringBuilder("", selectedExperiments.GetLength(0) * 8);

            //Save rerun settings.
            MyRerunSettings = criteria;

            //Make a text list of the selected experiments.
            foreach (Identifiable tempExperiment in selectedExperiments)
            {
                str.Append(tempExperiment.Name + Environment.NewLine);
            }
            MySelectedExperimentList = str.ToString();

            //Create a dictionary of all items.
            MyAllItems = new IdentifiableDictionary();
            foreach (Identifiable tempItem in allItems)
            {
                MyAllItems.Add(tempItem.ID, tempItem);
            }

            //Create a dictionary of the automatically selected items.
            MyCriteriaSelectedItems = new IdentifiableDictionary();
            foreach (Identifiable tempItem in criteriaSelectedItems)
            {
                MyCriteriaSelectedItems.Add(tempItem.ID, tempItem);
            }

            //Initialize dictionaries for manually added and removed items.
            MyManuallyAddedItems   = new IdentifiableDictionary();
            MyManuallyRemovedItems = new IdentifiableDictionary();

            MyCheckedListBox.TheCheckedListBox.Items.AddRange(allItems);

            //Check the automatically selected items.
            for (int i = 0; i < MyCheckedListBox.TheCheckedListBox.Items.Count; i++)
            {
                if (MyCriteriaSelectedItems.Contains(((Identifiable)MyCheckedListBox.TheCheckedListBox.Items[i]).ID))
                {
                    MyCheckedListBox.TheCheckedListBox.SetItemChecked(i, true);
                }
            }
            MyCheckedListBox.RefreshCounterText();

            //Listen to the ItemCheck event inside the actual checked list box.
            MyCheckedListBox.TheCheckedListBox.ItemCheck += new ItemCheckEventHandler(MyCheckedListBox_ItemCheck);

            //Initialize the global string builder which holds the log text.
            //(Need space for all the experiments plus some extra text.)
            MyText = new StringBuilder("", MySelectedExperimentList.Length + 1000);

            RefreshText();
        }
        private void CheckButton_Click(object sender, System.EventArgs e)
        {
            Identifiable [] checkedExperiments, allItems;
            RerunSettings   pickSettings;
            DataTable       rerunItemTable, allItemTable;
            RerunListForm   listForm;

            Identifiable [] selectedItems;

            try
            {
                //Store selected experiments.
                this.Cursor = Cursors.WaitCursor;

                DisplayStatus("Storing selected experiments...");

                checkedExperiments = new Identifiable[ExperimentList.TheCheckedListBox.CheckedItems.Count];
                for (int i = 0; i < ExperimentList.TheCheckedListBox.CheckedItems.Count; i++)
                {
                    checkedExperiments[i] = (Identifiable)ExperimentList.TheCheckedListBox.CheckedItems[i];
                }
                if (checkedExperiments.GetLength(0) < 1)
                {
                    this.Cursor = Cursors.Default;
                    MessageManager.ShowInformation("No experiments selected.", this);
                    return;
                }

                DisplayStatus("Clearing previous rerun experiments...");

                MyDataServer.ClearRerunExperiments();

                DisplayStatus("Adding new rerun experiments...");

                for (int i = 0; i < checkedExperiments.GetLength(0); i++)
                {
                    MyDataServer.AddRerunExperiment(checkedExperiments[i].ID);
                }

                //Read rerun settings.
                pickSettings = new RerunSettings();
                pickSettings.MissingGenotype        = MissingGenotypesCheckBox.Checked;
                pickSettings.MissingGenotypePercent = 100 - (int)MissingGenotypePercentage.Value;
                pickSettings.LowAlleleFrq           = AlleleFrqCheckBox.Checked;
                pickSettings.LowAlleleFrqPercent    = (int)AlleleFrqPercentage.Value;
                pickSettings.DuplicateErrors        = DuplicateErrorCheckBox.Checked;

                DisplayStatus("Processing rerun items...");

                //Get items to check.
                rerunItemTable = MyDataServer.GetRerunItems(MySessionSettings, pickSettings);

                DisplayStatus("Fetching all items...");

                //Fill item table with all items.
                allItemTable = MyDataServer.GetResultItems();
                allItems     = new Identifiable[allItemTable.Rows.Count];
                for (int i = 0; i < allItemTable.Rows.Count; i++)
                {
                    allItems[i] = new Identifiable(Convert.ToInt32(allItemTable.Rows[i]["item_id"]),
                                                   allItemTable.Rows[i]["identifier"].ToString());
                }

                DisplayStatus("Storing rerun items...");

                //Save the items which should be checked.
                selectedItems = new Identifiable[rerunItemTable.Rows.Count];
                for (int i = 0; i < rerunItemTable.Rows.Count; i++)
                {
                    selectedItems[i] = new Identifiable(Convert.ToInt32(rerunItemTable.Rows[i][0]), "");
                }

                DisplayStatus("Preparing display...");

                listForm = new RerunListForm(pickSettings, checkedExperiments, allItems, selectedItems);

                DisplayStatus("Finished, please wait...");

                this.Cursor = Cursors.Default;
                listForm.ShowDialog(this);

                DisplayStatus("Finished");
            }
            catch (Exception ex)
            {
                MessageManager.ShowError(ex, "Error when selecting items.", this);
            }
        }