private void btnAddRate_Click(object sender, EventArgs e) { if (ValidateRate() == false) return; double rate = Convert.ToDouble(txtRate.Text); Rate newRate = new Rate(0, ""); newRate.Value = rate; newRate.Name = rate + "%"; _caller.ImplementNewRate(newRate); this.Close(); }
public void ImplementNewRate(Rate newRate) { if (newRate == null) //user cancels { _selectedComboBox.SelectedIndex = 1; } else { foreach (ComboBox cbx in _listCbxRate) { AddNewRate(cbx, newRate); _selectedComboBox.SelectedIndex = _selectedComboBox.Items.IndexOf(newRate); } } }
private void AddNewRate(ComboBox cbx, Rate newRate) { if(cbx.Items.Count > 0) { cbx.Items.RemoveAt(cbx.Items.Count - 1); //remove custom rate option cbx.Items.Add(newRate); //add new rate cbx.Items.Add(new Rate(-1, "Custom Rate")); //add custom rate option } }