public WinForm() { InitializeComponent(); cbQueryOptions.DataSource = Enum.GetValues(typeof(QueryOptions)); cbQueryOptions.SelectedIndex = 0; //Inicialize PI Web API Wrapper piWebApi = new PIWebAPISearchWrapper("https://marc-web-sql/piwebapi/"); //Get PI Web API sources string array string[] sourceList = piWebApi.GetSources().ToArray(); //Create the checkbox array for storing the checkboxes checkBoxSources = new System.Windows.Forms.CheckBox[sourceList.Count()]; //Instantiate one checkbox per source int j = -1; int m = 0; for (int i = 0; i < checkBoxSources.Length; i++) { if (i < 42) { checkBoxSources[i] = new System.Windows.Forms.CheckBox(); checkBoxSources[i].AutoSize = true; //For each checkbox it needs to be added on a different location checkBoxSources[i].Location = new System.Drawing.Point(20 + 300 * j, 5 + 20 * m); checkBoxSources[i].Name = "cbSource" + i; checkBoxSources[i].Size = new System.Drawing.Size(79, 17); checkBoxSources[i].TabIndex = 0; checkBoxSources[i].Text = sourceList[i]; checkBoxSources[i].UseVisualStyleBackColor = true; //Add checkbox to the groupbox this.gbDataSources.Controls.Add(checkBoxSources[i]); if (i % 14 == 0) { j++; m = 0; } m++; } } }