private void comboRecType_SelectedIndexChanged(object sender, EventArgs e) { var selectedItem = (TextValueItem)((ComboBox)sender).SelectedItem; _recordTypeSel = (RecordType)selectedItem.Value; comboField.Items.Clear(); txtFieldSearch.Text = ""; txtFieldSearch.Enabled = false; foreach (var attr in _recordTypeSel.Attributes.OrderBy(x => x.Value).ToArray()) { var comboBoxItem = new TextValueItem { Text = attr.Value, Value = "Attributes." + attr.Key }; comboField.Items.Add(comboBoxItem); } if (comboField.Items.Count > 0) { var comboBoxItem = new TextValueItem { Text = "(all fields)", Value = "*" }; comboField.Items.Add(comboBoxItem); } LoadRecordsByType(_recordTypeSel); gridRecords.Enabled = true; comboField.Enabled = true; }
/// <summary> /// 枚举类型 转换成 TextValueItem 列表 /// </summary> /// <typeparam name="TEnum">枚举类型 T</typeparam> /// <param name="source">当前实例</param> /// <param name="defaulted">是否添加一条默认的数据 value = -1</param> /// <param name="defaultText"> text = 请选择</param> /// <returns>TextValueItem 列表</returns> public static List <TextValueItem> ToTextValueList <TEnum>(this TEnum source, bool defaulted, string defaultText = "请选择") where TEnum : struct { Type type = source.GetType(); if (!type.IsEnum) { throw new Exception("非枚举类型不能调用ToTextValueList()方法"); } List <TextValueItem> items = new List <TextValueItem>(); if (defaulted) { items.Add(new TextValueItem { Value = -1, Text = defaultText }); } Array values = Enum.GetValues(type); foreach (TEnum value in values) { TextValueItem item = new TextValueItem { Text = value.ToText(), Value = Convert.ToInt32(value) }; items.Add(item); } return(items); }
public void Init() { this.Items.Clear(); TextValueItem<VerifyCode>[] items = new TextValueItem<VerifyCode>[]{ new TextValueItem<VerifyCode>(VerifyCode.None , string.Empty ), new TextValueItem <VerifyCode>(VerifyCode.FP_AND_PW ,"指纹加密码"), new TextValueItem<VerifyCode>(VerifyCode.FP_AND_RF,"指纹加卡"), new TextValueItem<VerifyCode>(VerifyCode.FP_AND_PW_AND_RF, "指纹加卡加密码"), }; this.DataSource = items; this.DisplayMember = "Text"; this.DropDownStyle = ComboBoxStyle.DropDownList; this.SelectedIndex = 0; }
private void LoadRecordTypeBox() { RecordType[] recordTypes = null; using (var oH = new ObjectHelper(_dbSettings, _user)) { var result = oH.GetRecordTypes(); if (result.Success) { recordTypes = (RecordType[])result.Result; } } foreach (var rT in recordTypes.OrderBy(x => x.Name).ToArray()) { var comboBoxItem = new TextValueItem { Text = rT.Name, Value = rT }; comboRecType.Items.Add(comboBoxItem); } }