I have a list box in which there are around say 10 items. Now I select a few items on top(more than two), and a few items in mid. I want to create a list that contains the largest number of continuously selected items of these two different selections. that is if number few selected items on top is larger than number of few selected items in mid then few items on top should go to the list. How to do that? i have put a check to see for the continuity which is as below:
for (int i = 0; i < lb.SelectedIndices.Count - 1; i++)
{
if (lb.SelectedIndices[i] < lb.SelectedIndices[i + 1] - 1)
return false;
return true;
}
Just keep track of the the length of the current subsequence and when you encounter an index out of sequence, check against the longest consecutive subsequence seen so far.