How to highlight all rows in listbox between two index values?

Ken Ekholm 151 Reputation points
2023-03-17T11:15:21.7933333+00:00

Is it possible to highlight all rows in listbox between two index values with Visual C#?

If it possible how is it done?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,247 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.1K Reputation points
    2023-03-17T19:27:00.7166667+00:00

    For example, to highlight the items 3, 4 and 5:

    int index1 = 2;
    int index2 = 6;
    
    listBox1.SelectionMode = SelectionMode.MultiExtended;
    listBox1.SelectedItems.Clear( );
    
    for( int i = index1 + 1; i < index2; i++ )
    {
        listBox1.SelectedIndices.Add( i );
    }
    
    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful