tags:

views:

128

answers:

2

Hi

I am using a checked list box in my project c#.net windows application.

I want to sort the list box such that checked items should come first and unchecked displays after it.

How can i do it ? any code to do it ?

A: 

The quickest way is just two create two lists of checkboxes. Loop through all the checkboxes putting checked checkboxes into one list and unchecked into another. Then combine these lists. Now clear the the listbox and add the items from the new lists.

BobbyShaftoe
A: 

int checkedItemsCount = 0;

for (int i = 0; i < this.checkedListBox1.CheckedItems.Count; i++)
{
object checkedItem = this.checkedListBox1.CheckedItems[i]; this.checkedListBox1.Items.Remove(checkedItem); this.checkedListBox1.Items.Insert(checkedItemsCount, checkedItem); this.checkedListBox1.SetItemChecked(checkedItemsCount++,true);
}

this code will work fine.

Umesh BT