private void pgPara_SelectionChanged(object sender, DataRowSelectionChangedArgs e) { try { if (e.Row == null) { return; } var group = ((ConfigParaKeyValue)e.Row).Group; if (group == null) { ((ConfigParaKeyValue)e.Row).Group = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comboBoxParaGroup); } else { DropdownBoxHelper.SetGenericToComboBox(comboBoxParaGroup, group); } } catch (Exception ex) { MessageBox.Show(ex.Message); Loger.Error(ex); } }
/// <summary> /// 刷新数据 /// </summary> public override void RefreshData() { try { List <ConfigParaGroup> groups = this._configLogic.GetAllConfigParaGroup(); groups.Insert(0, this._allGroup); ConfigParaGroup selectedItem = null; if (comGroup.Items.Count > 0) { var oldSelectedItem = DropdownBoxHelper.GetGenericFromComboBox <ConfigParaGroup>(comGroup); if (oldSelectedItem != null) { var ret = (from tmpItem in groups where oldSelectedItem.ID == tmpItem.ID select tmpItem).ToList(); if (ret.Count > 0) { selectedItem = ret[0]; } } } if (selectedItem == null && groups.Count > 0) { selectedItem = groups[0]; } this.comGroup.SelectedIndexChanged -= this.comGroup_SelectedIndexChanged; try { DropdownBoxHelper.BindingIEnumerableGenericToComboBox <ConfigParaGroup>(comGroup, groups, nameof(ConfigParaGroup.Name), null); } finally { this.comGroup.SelectedIndex = -1; this.comGroup.SelectedIndexChanged += this.comGroup_SelectedIndexChanged; DropdownBoxHelper.SetGenericToComboBox(comGroup, selectedItem); } } catch (Exception ex) { Loger.Error(ex); } }
private void btnSetGenericToComboBox_Click(object sender, EventArgs e) { DropdownBoxHelper.SetGenericToComboBox(comboBox1, items[1]); }