0

I have a list box on a Windows form in Visual Studio 2010 and would like the user to click a button and have the items in the list box sorted. E.g Alphabetical Order, Numerical Order.

I am new to C# and aren't sure where to start with writing the code for the sort button. I would very much appreciate if you could provide me with a starting point how to go about doing this.

This is the data for the list box when data is being added to it:

public Sale GetItemData()
{
    Sale newItem = new Sale(Convert.ToInt32(txtID.Text), StartingDate.Text, ClosingDate.Text, txtLocation.Text, Convert.ToInt32(txtDisplaySpaces.Text), txtExclusive.Text, txtME.Text, Convert.ToInt32(txtDisplayStands.Text));
    return newItem;
}

This is the sort by ID button that I wish to use to sort the list box:

private void btnSortSalesbyID_Click(object sender, EventArgs e)
{

}

Thanks.

Michael Page
  • 17
  • 1
  • 1
  • 4

2 Answers2

0

Take the items from the ListBoxand store them in a List then sort the List and put it back into the ListBox

Dzm2012
  • 123
  • 1
  • 7
  • I think this is better suited as a comment. If choosing to supply a full answer, add some code. – Kris Aug 21 '14 at 11:35
0

See Chris Valentine's answer here: Sorting a list of items in a list box

You will probably have to write a custom Sort() routine.

Community
  • 1
  • 1
Derek
  • 373
  • 3
  • 12