i want to fill the listbox so that when ive added everything the data is in order.


int index = 0;
if (priority < PriorityList.SelectedItem)
{
while (priority < PriorityList.SelectedItem)
{
index++;
}
PriorityList.Items.Add(priority);
}
else
PriorityList.Items.Add(priority);

the problem im having is keeping track of the index. if the item is smaller than the selected item the selected item moves onto the next index until it gets to a point