In this example, I’ll show How to sort items of Listbox.
Step 1: Add a button and listBox to Form.
Step 2: Add code in Form_Load event
1 2 3 4 5 6 7 8 9 10 11 12 |
private void Form1_Load(object sender, EventArgs e) { listBox1.Items.Add("C#"); listBox1.Items.Add("Java"); listBox1.Items.Add("C++"); listBox1.Items.Add("Python"); listBox1.Items.Add("Pascal"); listBox1.Items.Add("Delphi"); listBox1.Items.Add("Visual Basic"); } |
Step 3: Add code in Button1_Click event.
1 2 3 4 5 6 |
private void button1_Click(object sender, EventArgs e) { listBox1.Sorted = true; } |