vendredi 14 août 2015

How can I check the first checkbox after no checkboxes checked in a checkedListBox?

I hope you understand the question.

So basically I have a checkedListBox with checkboxes named:

First (unchecked)

Second (unchecked)

Third (checked)

Fourth (unchecked)

Now what I want to do here is to check the first one automatically when I uncheck the last checked checkbox.

And a maybe important note:

I made a code so that you can select only one of the checkboxes BY CLICKING ONCE. But when you double-click it, it unchecks......... that's uh.. what I don't want.. And I use Windows Forms Application..

Is it possible?

EDIT:

The code I have when the you check/select a checkbox:

private void checkedListBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            //#DONTJUDGEME
            switch (checkedListBox3.SelectedIndex)
            {
                case 0:
                    checkedListBox3.SetItemChecked(0, true);
                    checkedListBox3.SetItemChecked(1, false);
                    checkedListBox3.SetItemChecked(2, false);
                    checkedListBox3.SetItemChecked(3, false);
                    break;
                case 1:
                    checkedListBox3.SetItemChecked(0, false);
                    checkedListBox3.SetItemChecked(1, true);
                    checkedListBox3.SetItemChecked(2, false);
                    checkedListBox3.SetItemChecked(3, false);
                    break;
                case 2:
                    checkedListBox3.SetItemChecked(0, false);
                    checkedListBox3.SetItemChecked(1, false);
                    checkedListBox3.SetItemChecked(2, true);
                    checkedListBox3.SetItemChecked(3, false);
                    break;
                case 3:
                    checkedListBox3.SetItemChecked(0, false);
                    checkedListBox3.SetItemChecked(1, false);
                    checkedListBox3.SetItemChecked(2, false);
                    checkedListBox3.SetItemChecked(3, true);
                    break;
            }

            // #IGNORE-STUFF
            if (File.Exists(openFileDialog1.FileName) && Path.GetFileName(openFileDialog1.FileName) == "KFServer.exe")
            {
                string confingFile = Directory.GetParent(Directory.GetParent(Directory.GetParent(Path.GetFullPath(openFileDialog1.FileName)).ToString()).ToString()).ToString() + @"\KFGame\Config\PCServer-KFGame.ini";
                string text = File.ReadAllText(confingFile);

                int i = 0;

                while (!File.ReadLines(confingFile).Skip(i).Take(1).First().Contains("GameDifficulty="))
                {
                    i++;
                }

                if (checkedListBox3.GetItemChecked(0) == true)
                    text = text.Replace(File.ReadLines(confingFile).Skip(i).Take(1).First(), "GameDifficulty=0.000000");

                if (checkedListBox3.GetItemChecked(1) == true)
                    text = text.Replace(File.ReadLines(confingFile).Skip(i).Take(1).First(), "GameDifficulty=1.000000");

                if (checkedListBox3.GetItemChecked(2) == true)
                    text = text.Replace(File.ReadLines(confingFile).Skip(i).Take(1).First(), "GameDifficulty=2.000000");

                if (checkedListBox3.GetItemChecked(3) == true)
                    text = text.Replace(File.ReadLines(confingFile).Skip(i).Take(1).First(), "GameDifficulty=3.000000");

                File.WriteAllText(confingFile, text);
            }
        }




Aucun commentaire:

Enregistrer un commentaire