检查的radiobutton在窗体上没有出现

时间:2016-06-15 19:32:27

标签: c# winforms

在窗体表格中未检查已检查的单选按钮。enter image description here

我已经使用消息框对其进行了测试,并且已经检查了...

您可以要求更多代码/信息。 语言是法语。

感谢您的帮助

新图:根据我的sql数据库,控制台输出是正确的。 enter image description here

// LOAD RADIOBUTTON
                SQLCommand.CommandText = ChargementRadiobuttonCommandText;
                reader = SQLCommand.ExecuteReader();

                // Rempli une liste avec les réponses provenant de la base de donné
                while (reader.Read())
                {
                    ReponsesRadioButton.Add(reader["ReponseRadioButton"].ToString());
                }

                //foreach (string current in ReponsesRadioButton)
                //{
                //    MessageBox.Show(current);
                //}
                //MessageBox.Show("0: " + ReponsesRadioButton[0]);
                //MessageBox.Show("11 " + ReponsesRadioButton[11]);
                //MessageBox.Show("cathegorie: " + SessionQuestionGeneral.getintCathegorieActuel().ToString());

                //nombreDeQuestions = 0;

                //switch (SessionQuestionGeneral.getintCathegorieActuel())
                //{
                //    case 1:
                //        nombreDeQuestions = 12;
                //        break;

                //    case 2:
                //        nombreDeQuestions = 7;
                //        break;

                //    case 3:
                //        nombreDeQuestions = 7;
                //        break;

                //    case 4:
                //        nombreDeQuestions = 3;
                //        break;
                //}

                //for (int questionDeLaFenetre = 0; questionDeLaFenetre < nombreDeQuestions; questionDeLaFenetre++)
                //{ 

                foreach (string ReponseRadioButton in ReponsesRadioButton)
                { 
                //

                    switch (ReponseRadioButton)
                    {
                        case "En accord":
                            listRadioButtonEnAccord[iterationQuestion].Checked = true;

                            break;
                        case "En desaccord":
                            listRadioButtonEndesaccord[iterationQuestion].Checked = true;
                            break;

                        case "Non applicable":
                            listRadioButtonNonapplicable[iterationQuestion].Checked = true;
                            break;
                    }
                    //MessageBox.Show(iterationQuestion.ToString() + " " + ReponseRadioButton);
                    iterationQuestion++;

                }
                //MessageBox.Show("listRadioButtonEnAccord10 " + listRadioButtonEnAccord[10].Checked.ToString());
                //MessageBox.Show("listRadioButtonEndesaccord10 " + listRadioButtonEndesaccord[10].Checked.ToString());
                //MessageBox.Show("listRadioButtonNonapplicable10 " + listRadioButtonNonapplicable[10].Checked.ToString());

                //MessageBox.Show("listRadioButtonEnAccord11 " + listRadioButtonEnAccord[11].Checked.ToString());
                //MessageBox.Show("listRadioButtonEndesaccord11 " + listRadioButtonEndesaccord[11].Checked.ToString());
                //MessageBox.Show("listRadioButtonNonapplicable11 " + listRadioButtonNonapplicable[11].Checked.ToString());
                reader.Close();
                ReponsesRadioButton.Clear();
                iterationQuestion = 0;

                // LOAD LABEL cathegorie
                SQLCommand.CommandText = cathegorieCommandText;
                reader = SQLCommand.ExecuteReader();

                while (reader.Read())
                {
                    cathegorieText.Text = reader["nomCathegoriequestiongenerale"].ToString();
                }
                reader.Close();

2 个答案:

答案 0 :(得分:0)

您是否尝试过以下代码?

this.Update();

this.Refresh();

执行此操作以使用Form类中的某些方法更新表单。

答案 1 :(得分:0)

我解决了这个问题:reponseGroupBox[iterationQuestion].Controls.OfType<RadioButton>() 似乎更有效。

foreach (string ReponseRadioButton in ReponsesRadioButton)
                {
                    foreach (RadioButton radioButtonActuel in reponseGroupBox[iterationQuestion].Controls.OfType<RadioButton>()) // Pour chaque RadioButton du reponseGroupBox associé à questionActuel
                    {
                            if (radioButtonActuel.Text == "En accord" && ReponseRadioButton == "En accord")
                            {
                                radioButtonActuel.Checked = true;
                            }

                            if (radioButtonActuel.Text == "En desaccord" && ReponseRadioButton == "En desaccord")
                            {
                                radioButtonActuel.Checked = true;
                            }

                            if (radioButtonActuel.Text == "Non applicable" && ReponseRadioButton == "Non applicable")
                            {
                                radioButtonActuel.Checked = true;
                            }
                    }
                    iterationQuestion++;
                }