private void btnAdd_Click(object sender, EventArgs e) { if (Conditionals == null) { return; } InventoryConditional cond = new InventoryConditional(); Conditionals.Add(cond); UpdateUI(); SelectedConditional = cond; }
private void btnMoveDown_Click(object sender, EventArgs e) { if (SelectedConditional == null) { return; } int Index = Conditionals.IndexOf(SelectedConditional); if (Index == Conditionals.Count - 1) { return; // Can't move down anymore. } InventoryConditional higher = Conditionals[Index]; InventoryConditional lower = Conditionals[Index + 1]; Conditionals[Index] = lower; Conditionals[Index + 1] = higher; lbConditionals.Refresh(); }
private void UpdateUI() { Updating = true; InventoryConditional previous = SelectedConditional; lbConditionals.Items.Clear(); if (Conditionals == null) { btnAdd.Enabled = false; btnRemove.Enabled = false; } else { btnAdd.Enabled = true; btnRemove.Enabled = true; lbConditionals.Items.AddRange(Conditionals.ToArray()); if (previous != null && lbConditionals.Items.Contains(previous)) { lbConditionals.SelectedItem = previous; } } if (SelectedConditional == null) { cbItemName.Text = ""; cbItemName.Enabled = false; cbConditionalType.SelectedItem = null; cbConditionalType.Enabled = false; nudValue.Value = 0; nudValue.Enabled = false; btnMoveUp.Enabled = false; btnMoveDown.Enabled = false; } else { cbItemName.Text = SelectedConditional.InventoryItem; cbItemName.Enabled = true; cbConditionalType.SelectedValue = SelectedConditional.ComparisonOperator; cbConditionalType.Enabled = true; nudValue.Value = SelectedConditional.Value; nudValue.Enabled = true; int Index = Conditionals.IndexOf(SelectedConditional); if (Index == 0) { btnMoveUp.Enabled = false; } else { btnMoveUp.Enabled = true; } if (Index == Conditionals.Count - 1) { btnMoveDown.Enabled = false; } else { btnMoveDown.Enabled = true; } } Updating = false; }