using System;
using System.Windows.Forms;

namespace Invert_Selection
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            for (int x = 0; x < listBox1.Items.Count; x++)
            {
                if (listBox1.GetSelected(x) == true)
                    listBox1.SetSelected(x, false);
                else
                    listBox1.SetSelected(x, true);
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            listBox1.SelectionMode = SelectionMode.MultiExtended;

            listBox1.SetSelected(0, true);
            listBox1.SetSelected(2, true);
            listBox1.SetSelected(4, true);
            listBox1.SetSelected(6, true);
        }
    }
}