private void buttonAdd_Click(object sender, EventArgs e) { bool bFind = false; foreach (var sort in listBox1.Items) { SortClass sc = (SortClass)sort; if (sc.fieldName == comboBox1.Text) { bFind = true; break; } } if (!bFind) { SortClass sc = new SortClass(); sc.fieldName = comboBox1.Text; if (comboBox2.SelectedIndex == 0) { sc.sortType = SortType.Asc; } else { sc.sortType = SortType.Desc; } listBox1.Items.Add(sc); listBox1.SelectedIndex = listBox1.Items.Count - 1; } }
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)//显示 { if (listBox1.SelectedIndex < 0) { return; } if (listBox1.SelectedIndex == 0) { button3.Enabled = false; } else { button3.Enabled = true; } if (listBox1.SelectedIndex == listBox1.Items.Count - 1) { button4.Enabled = false; } else { button4.Enabled = true; } SortClass sc = (SortClass)listBox1.SelectedItem; comboBox1.SelectedIndex = comboBox1.FindString(sc.fieldName); if (sc.sortType == SortType.Desc) { comboBox2.SelectedIndex = 1; } else { comboBox2.SelectedIndex = 0; } }
public SortClass Clone() { SortClass sc = new SortClass(); sc.fieldName = this.fieldName; sc.sortType = this.sortType; return(sc); }
private void button3_Click(object sender, EventArgs e)//up { int oldIndex = listBox1.SelectedIndex; if (oldIndex <= 0) { return; } SortClass sc = (SortClass)listBox1.SelectedItem; SortClass sc_up = (SortClass)listBox1.Items[oldIndex - 1]; listBox1.Items[oldIndex - 1] = sc; listBox1.Items[oldIndex] = sc_up; listBox1.SelectedIndex = oldIndex - 1; }
private void button4_Click(object sender, EventArgs e)//down { int oldIndex = listBox1.SelectedIndex; if (oldIndex < 0) { return; } if (oldIndex > listBox1.Items.Count - 2) { return; } SortClass sc = (SortClass)listBox1.SelectedItem; SortClass sc_down = (SortClass)listBox1.Items[oldIndex + 1]; listBox1.Items[oldIndex + 1] = sc; listBox1.Items[oldIndex] = sc_down; listBox1.SelectedIndex = oldIndex + 1; }