private void ListBox1_SelectedIndexChanged(object sender, EventArgs e) { ListBox listBox = sender as ListBox; KeyValueProperty keyValueProperty = this.panel3.Controls["_keyvalueProperty"] as KeyValueProperty; LibKeyValue keyValue = listBox.Items[listBox.SelectedIndex] as LibKeyValue; keyValueProperty.SetPropertyValue(keyValue, null); }
/// <summary> /// 新增项事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button1_Click(object sender, EventArgs e) { LibKeyValue keyValue = new LibKeyValue(); keyValue.ID = Guid.NewGuid().ToString(); keyValue.Key = string.Format("itemkey{0}", this.listBox1.Items.Count + 1); keyValue.Value = string.Format("itemvalue{0}", this.listBox1.Items.Count + 1); this.listBox1.Items.Add(keyValue); this.listBox1.SelectedItem = keyValue; KeyValueProperty keyValueProperty = this.panel3.Controls["_keyvalueProperty"] as KeyValueProperty; keyValueProperty.SetPropertyValue(keyValue, null); }
private void ListBox_SelectedIndexChanged(object sender, EventArgs e) { ListBox listBox = sender as ListBox; Control container = listBox.Parent; KeyValueProperty keyValueProperty = container.Controls["_keyvalueProperty"] as KeyValueProperty; LibKeyValue keyValue = listBox.Items[listBox.SelectedIndex] as LibKeyValue; keyValueProperty.SetPropertyValue(keyValue, null); if (!string.IsNullOrEmpty(keyValue.FromkeyValueID)) { keyValueProperty.Enabled = false; } else { keyValueProperty.Enabled = true; } }
/// <summary>键值对窗体中的添加按钮事件</summary> /// <param name="sender"></param> /// <param name="e"></param> private void Addbtn_Click(object sender, EventArgs e) { Control ctl = sender as Control; Control container = ctl.Parent.Parent; ListBox box = container.Controls["_listbox"] as ListBox; LibKeyValue keyValue = new LibKeyValue(); keyValue.ID = Guid.NewGuid().ToString(); keyValue.Key = string.Format("itemkey{0}", box.Items.Count + 1); keyValue.Value = string.Format("itemvalue{0}", box.Items.Count + 1); box.Items.Add(keyValue); //KeyValueProperty keyValueProperty = new KeyValueProperty(); //keyValueProperty.Dock = DockStyle.Fill; KeyValueProperty keyValueProperty = container.Controls["_keyvalueProperty"] as KeyValueProperty; keyValueProperty.SetPropertyValue(keyValue, null); //container.Controls["keyvalueContains"].Controls.Add(keyValueProperty); }