static string GetComboBoxTextState(ComboBoxText container) { ComboBox combobox = container.ComboBox; Hashtable table = new Hashtable(); table["style"] = combobox.DropDownStyle.ToString(); table["text"] = combobox.Text; return(container.GetType().ToString() + ":" + StringUtil.BuildParameterString(table, ',', '=', "url")); }
static void SetComboBoxTextState(ComboBoxText container, string strText, object default_value) { string strState = ""; ComboBox combobox = container.ComboBox; if (string.IsNullOrEmpty(strText) == true && default_value != null) { if (default_value is int) { combobox.SelectedIndex = (int)default_value; } else if (default_value is string) { combobox.Text = (string)default_value; } else { throw new ArgumentException("ComboBoxText 的缺省值应当为 int 或 string 类型", "default_value"); } return; } if (IsType(strText, container, out strState) == false) { return; } if (string.IsNullOrEmpty(strState) == false) { Hashtable table = StringUtil.ParseParameters(strState, ',', '=', "url"); string strStyle = (string)table["style"]; string strValue = (string)table["text"]; ComboBoxStyle style; Enum.TryParse <ComboBoxStyle>(strStyle, out style); if (string.IsNullOrEmpty(strValue) == false) { combobox.Text = strValue; if (combobox.Text != strValue) { combobox.Items.Add(strValue); combobox.Text = strValue; } } } }
static string GetComboBoxTextState(ComboBoxText container) { ComboBox combobox = container.ComboBox; Hashtable table = new Hashtable(); table["style"] = combobox.DropDownStyle.ToString(); table["text"] = combobox.Text; return container.GetType().ToString() + ":" + StringUtil.BuildParameterString(table); }
static void SetComboBoxTextState(ComboBoxText container, string strText, object default_value) { string strState = ""; ComboBox combobox = container.ComboBox; if (string.IsNullOrEmpty(strText) == true && default_value != null) { if (default_value is int) combobox.SelectedIndex = (int)default_value; else if (default_value is string) combobox.Text = (string)default_value; else throw new ArgumentException("ComboBoxText 的缺省值应当为 int 或 string 类型", "default_value"); return; } if (IsType(strText, container, out strState) == false) return; if (string.IsNullOrEmpty(strState) == false) { Hashtable table = StringUtil.ParseParameters(strState); string strStyle = (string)table["style"]; string strValue = (string)table["text"]; ComboBoxStyle style; Enum.TryParse<ComboBoxStyle>(strStyle, out style); if (string.IsNullOrEmpty(strValue) == false) { combobox.Text = strValue; if (combobox.Text != strValue) { combobox.Items.Add(strValue); combobox.Text = strValue; } } } }