Mình đã tạo một giao diện đơn giản gồm có:
- 1 textbox để nhập item
- 2 button để thêm và xóa item
- 1 listbox để hiển thị
Sự kiện click của 2 nút được viết như sau :
private void button1_Click(object sender, EventArgs e)
{
//thêm item vào listbox
listBox1.Items.Add(textBox1.Text);
//sau khi thêm vào thì mình xóa text ở textbox đi
textBox1.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
//xóa item được chọn trong listbox
listBox1.Items.Remove(listBox1.SelectedItem);
}
Mọi chuyện thật đơn giản phải không ?
Source demo: Download
Không có nhận xét nào:
Đăng nhận xét