繁体   English   中英

Windows窗体上未选中“已选中”单选按钮

[英]Checked radiobutton doesn`t appear checked on the windows form

Windows窗体上未选中已选中的单选按钮。 在此处输入图片说明

我已经用一个消息框对其进行了测试,并且其书面内容已选中...

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

感谢帮助

新图片:根据我的sql数据库,控制台输出正确。 在此处输入图片说明

// 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();

您是否尝试过以下代码?

this.Update();

要么

this.Refresh();

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

我已解决此问题: 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++;
                }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM