Are you trying to see the list sorted while adding each new item or on click
of a button?
if you are trying to sort while adding items to the list, (i assume you are
using a code like ddList1.Items.Add(new ListItem("new item")) )
1) Init a counter
int ListItemCounter = 0;
2) loop through the list collection and incriment ListItemCounter
foreach (ListItem li in ddList1.Items)
{
ListItemCounter ++;
3) Check if Item.Text > "new item" , if so, insert new item at
ListItemCounter - 1
ddList1.Items.Insert(ListItemCounter-1,new ListItem("new item")) )
this logic will check each item currently in the list and will insert the
new item when it find a larger value..
The initial list should be sorted alphabetically for this to work..
"benoit" wrote:
Hi,
I have this ListBox in which the Itemciollection can be manipulated by the
user (items can be added one way or another, and moved to other listboxes).
Is there any way that I can get this collection to be sorted alphabetically?
Thx