private void btnAddManual_Click(object sender, EventArgs e) { validations myVal = new validations(); if (myVal.intValidation((txtManualNumber.Text))) { List <int> _items = new List <int>(); int addNumber = int.Parse(txtManualNumber.Text); if (listBoxElements.DataSource != null) { foreach (var obj in (List <int>)listBoxElements.DataSource) { if (obj != addNumber) { _items.Add(obj); } } _items.Add(addNumber); } else { _items.Add(addNumber); } listBoxElements.DataSource = _items; txtManualNumber.Text = ""; label1.Text = "List of Numbers to be Use"; } else { MessageBox.Show("Only numbers please", "Error", MessageBoxButtons.OK); txtManualNumber.Text = ""; } }
private void btnFind_Click(object sender, EventArgs e) { validations myVal = new validations(); if (myVal.intValidation(txtFind.Text.ToString())) { string result = "100"; foreach (Control control in this.groupBox1.Controls) { if (control is RadioButton) { RadioButton myRadio = control as RadioButton; if (myRadio.Checked) { result = myRadio.Text; } } } randomNumbers myRnd = new randomNumbers(); int[] myElements = myRnd.arrayElements(int.Parse(result)); Simple_merge_sort mySort = new Simple_merge_sort(); listBox2.DataSource = myElements.ToArray(); mySort.sort(myElements); List <string> _items = new List <string>(); // <-- Add this _items = new List <string>(); // <-- Add this foreach (int i in myElements) { _items.Add(i.ToString()); } listBox1.DataSource = _items; SimpleBinarySearch myBinarySearch = new SimpleBinarySearch(); if (myBinarySearch.find(myElements, int.Parse(txtFind.Text))) { int myIndex = listBox1.FindString(txtFind.Text); listBox1.SetSelected(myIndex, true); MessageBox.Show("Value Found: " + txtFind.Text.ToString(), "Error", MessageBoxButtons.OK); } else { MessageBox.Show("Value Not Found", "Error", MessageBoxButtons.OK); } } else { MessageBox.Show("Must type a enter value, thx", "Error", MessageBoxButtons.OK); } }