void textBoxStatus_TextChanged(object sender, EventArgs e) { string sTemp = ""; foreach (char c in textBoxStatus.Text) { if (IsHex(c)) { sTemp += c; } } textBoxStatus.Text = sTemp; if (!string.IsNullOrEmpty(sTemp.Trim())) { _comboBoxStatusEnable = false; int nValue = Convert.ToInt32(sTemp, 16); ServiceStatusItem i = ServiceStatusItems.Find(item => Convert.ToInt32(item.Value) == nValue); if (i != null) { comboBoxStatus.Text = i.Name; } else { comboBoxStatus.Text = _sUserDefined; } _comboBoxStatusEnable = true; } }
void comboBoxStatus_SelectedIndexChanged(object sender, EventArgs e) { if (_comboBoxStatusEnable) { ServiceStatusItem item = comboBoxStatus.SelectedItem as ServiceStatusItem; if (Convert.ToInt32(item.Value) == -1) { textBoxStatus.Text = "0000"; } else { textBoxStatus.Text = item.ToHexValue(); } } }
public void InitializeServiceStatusItems() { comboBoxStatus.Items.Clear(); foreach (ServiceStatusItem item in ServiceStatusItems) { comboBoxStatus.Items.Add(item); } comboBoxStatus.SelectedIndex = 0; // Find the user defined item in the list (-1) ServiceStatusItem i = ServiceStatusItems.Find(item => Convert.ToInt32(item.Value) == -1); if (i != null) { _sUserDefined = i.Name; } }