c# - 迭代datarepeater中所有行的最佳方法?

时间:2017-01-17 09:47:17

标签: c# winforms datarepeater

private void exam_Load(object sender, EventArgs e)
    {
        GetCount();

        MySqlConnection con = new MySqlConnection("server = localhost; user id = root; password =; database = dbtest1;");
        MySqlCommand cmd = new MySqlCommand("SELECT question, question_no, choice1, choice2, choice3, choice4 from quiz_tions where quiz_id = '" + lid + "' ORDER BY RAND() LIMIT " + count + ";", con);
        MySqlDataAdapter sda = new MySqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        sda.Fill(dt);

        label5.DataBindings.Add("Text", dt, "question");
        label6.DataBindings.Add("Text", dt, "question_no");
        rb1.DataBindings.Add("Text", dt, "choice1");
        rb2.DataBindings.Add("Text", dt, "choice2");
        rb3.DataBindings.Add("Text", dt, "choice3");
        rb4.DataBindings.Add("Text", dt, "choice4");
        dataRepeater1.DataSource = dt;

        LoadData();


        label1.Text = qtitle;
        label3.Text = qtype;
    }

我的表单上有DataRepeater控件,使用上面的代码填充。每次执行此代码。 。

private void button3_Click(object sender, EventArgs e)
    {
        foreach (DataRepeaterItem c in dataRepeater1.Controls)
        {
            ss += ((Label)c.Controls["label5"]).Text + "\n";
        }
        MessageBox.Show(ss);
        ss = "";
    }

当我在单击按钮之前单击不同的行(有时是3行,有时是4行)时,它给出了不同的结果,并且它并不总是正确的,因为当我执行它时,我的DataRepeater控件上有5行。为什么会这样?迭代DataRepeater行的正确方法是什么?

P.S。与我的帖子无关的另一个问题(可能)是每当我向下/向上滚动DataRepeater时,有时它会自动检查列表中的随机RadioButton。这个控件出了什么问题?

1 个答案:

答案 0 :(得分:1)

如果您使用 dispatch_async(dispatch_get_main_queue()) { () -> Void in let activityViewController : UIActivityViewController = UIActivityViewController( activityItems: [text!], applicationActivities: nil) // This line remove the arrow of the popover to show in iPad activityViewController.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection() activityViewController.popoverPresentationController?.sourceRect = CGRect(x: 150, y: 150, width: 0, height: 0) // Anything you want to exclude activityViewController.excludedActivityTypes = [ UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo ] self.presentViewController(activityViewController, animated: true, completion: nil) } 多行,则应使用TextBox代替\r\n

  

Windows文本框需要CRLF作为行终止符,而不仅仅是LF。

您可以使用\n

\r\n

ss += ((Label)c.Controls["label5"]).Text + "\r\n";

System.Environment.NewLine

ss += ((Label)c.Controls["label5"]).Text + System.Environment.NewLine;

StringBuilder