how to sort the values of listbox
i want to sort the values of listbox, both in ascending and descending order
but in the following code there is some error... pls help
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
ArrayList list1 = new ArrayList();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add(textBox1.Text);
list1.add(textBox1.Text);
textBox1.Clear();
}
private void button2_Click(object sender, EventArgs e)
{
list1.Sort();
Object[] arr = list1.ToArray();
listBox2.Items.Clear();
listBox2.Items.AddRange(arr);
list1.Reverse();
Object[] arr1 = list1.ToArray();
listBox3.Items.Clear();
listBox3.Items.AddRange(arr1);
}