How to add items to a specific index in a listbox
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: How to add items to a specific index in a listbox

  1. #1
    Join Date
    Mar 2012
    Posts
    7

    How to add items to a specific index in a listbox

    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

  2. #2
    Join Date
    Mar 2012
    Posts
    7

    Re: How to add items to a specific index in a listbox

    thing submitted before i was finished and i cant find the edit post button. but to continue ...until it gets to a point where either its at the end of the list making the current number to add the smallest or when it finds a number in the list that its the same or larger than so it will add it to that index. if a number thats the largest so far it will get added to the top

  3. #3
    Join Date
    Jun 2008
    Posts
    2,477

    Re: How to add items to a specific index in a listbox

    Why don't you just sort the items collection?

    http://msdn.microsoft.com/en-us/libr...ox.sorted.aspx
    If you liked my post go ahead and give me an upvote so that my epee.... ahem, reputation will grow.

    Yes; I have a blog too - http://the-angry-gorilla.com/

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center