private void DirectInputValue(BtnTag tag) { if (tag.ComboBox.Tag != null && tag.ComboBox.Tag is IEnumerable) { IEnumerable eable = tag.ComboBox.Tag as IEnumerable; if (eable is object[]) { tag.ListBox.BeginUpdate(); tag.ListBox.Items.AddRange(eable as object[]); tag.ListBox.EndUpdate(); } else { foreach (object v in eable) { tag.ListBox.Items.Add(v); } } } else { if (IsRefType(_comboxes[tag.ComboBox].BindingAttribute.SemanticType)) { object v = null; if (_comboxes[tag.ComboBox].Editor.TryParse(tag.ComboBox.Text, out v)) { if (v != null) { if (v.GetType().BaseType.Equals(typeof(Array))) { foreach (object vi in v as IEnumerable) { tag.ListBox.Items.Add(vi); } } else { tag.ListBox.Items.Add(v); } } } } else { tag.ListBox.Items.Add(tag.ComboBox.Text); } } }
void delBtn_Click(object sender, EventArgs e) { BtnTag tag = (sender as Button).Tag as BtnTag; ListBox lstbox = tag.ListBox as ListBox; if (lstbox.SelectedIndices.Count == 0) { return; } int idx = lstbox.SelectedIndex; lstbox.Items.RemoveAt(lstbox.SelectedIndex); if (idx > 0 && idx < lstbox.Items.Count) { lstbox.SelectedIndex = idx; } }
void addBtn_Click(object sender, EventArgs e) { BtnTag tag = (sender as Button).Tag as BtnTag; //从其它Action帮定值 if (tag.ComboBox.Tag is BindingScriptObject) { BindValueByAction(tag); } else { DirectInputValue(tag); } // tag.ComboBox.Text = string.Empty; tag.ComboBox.Tag = null; }
private void SetBtnAttribute(BtnTag bt) { switch (bt) { case BtnTag.ADD: Btn_Add.Tag = "add"; Btn_Add.Text = "添 加"; break; case BtnTag.UPDATE: Btn_Add.Tag = "update"; Btn_Add.Text = "修 改"; break; case BtnTag.DEL: Btn_Add.Tag = "del"; Btn_Add.Text = "删 除"; break; } }
private void BindValueByAction(BtnTag tag) { // }