无法将项目添加到listview

时间:2015-10-14 16:27:29

标签: c# .net

我制作的ac#项目列出了ListViews中的某些内容,但是ListViews有点烦人,他们每次都不工作,有时候输入是正确的,可以显示在MessageBoxListBox,但尝试将其添加到ListBox时没有任何反应,这是我的代码,按下按钮时没有任何反应。

 private async void button2_Click(object sender, EventArgs e)
    {


        if(shouldirefresh == true)
        {
            button2.Enabled = false;
            checkBox1.Enabled = false;
            checkBox2.Enabled = false;
            checkBox3.Enabled = false;
            checkBox4.Enabled = false;
            checkBox5.Enabled = false;
            checkBox6.Enabled = false;
            pictureBox1.Visible = true;
            webBrowser1.Refresh();
            await td(3500);
        }


        checkBox1.Text = "Highlight -50%";
        checkBox2.Text = "Highlight 100%";
        checkBox3.Text = "Highlight 50%";
        pictureBox1.Visible = true;
        min50 = 0;
        max100 = 0;
        eq50 = 0;
        listView1.Items.Clear(); 
        listBox1.Items.Clear(); listBox2.Items.Clear(); listBox3.Items.Clear(); listBox4.Items.Clear();
        lsttit.Clear(); lstpoint.Clear(); lstmaxwosl.Clear(); lstmax.Clear();
        HtmlDocument doc = this.webBrowser1.Document;
        doc = webBrowser1.Document;
        var links = PulseVar.myrodoc.GetElementsByTagName("td");
        foreach (HtmlElement link in links)
        {


            if (link.GetAttribute("className") == "title")
            {

                lsttit.Add(link.InnerText);

            }
            else if (link.GetAttribute("className") == "point" || link.GetAttribute("className") == "point tekort")
            {
                lstpoint.Add(link.InnerText);
            }
            else if (link.GetAttribute("className") == "max" || link.GetAttribute("className") == "max tekort")
            {
                string RM = link.InnerText.Remove(0, 1);
                lstmax.Add(RM);
            }
            else if (link.GetAttribute("className") == "date")
            {
                datez.Add(link.InnerText);
            }
           else if(link.GetAttribute("className") == "average")
            {

                lstav.Add(link.InnerText);

            }
            else if(link.GetAttribute("className") == "comment")
            {
                if(link.InnerText == "&nbsp")
                {
                    lstcomment.Add("  ");
                }
                else
                {
                    lstcomment.Add(link.InnerText);
                }
            }
            else if(link.GetAttribute("className") == "TeacherTitle")
            {
                this.Text = "Myro ~ " + link.InnerText;

            }


        }

        for (int i = 0; i <= lsttit.Count - 1; i++)
        {

            ListViewItem d = new ListViewItem(lsttit[i]);

            try
            {
                if (decimal.Parse(lstpoint[i]) < (decimal.Parse(lstmax[i]) / 2))
                {

                    min50++;

                    d.SubItems.Add(lstpoint[i] + "/" + lstmax[i]);

                    if (checkBox1.Checked == true)
                    {
                        d.ForeColor = Color.Red;
                    }
                }
                else if (decimal.Parse(lstpoint[i]) == (decimal.Parse(lstmax[i])))
                {
                    //listView2.Items.Add(lstpoint[i] + "/" + lstmax[i]);
                    d.SubItems.Add(lstpoint[i] + "/" + lstmax[i]);
                    if (checkBox2.Checked == true)
                    {
                        d.ForeColor = Color.Green;

                    }
                    max100++;

                }
                else if (decimal.Parse(lstpoint[i]) == (decimal.Parse(lstmax[i]) / 2))
                {
                    //listView2.Items.Add(lstpoint[i] + "/" + lstmax[i]);
                    d.SubItems.Add(lstpoint[i] + "/" + lstmax[i]);
                    if (checkBox3.Checked == true)
                    {
                        d.ForeColor = Color.Yellow;
                    }
                    eq50++;
                }
                else
                {
                    d.SubItems.Add(lstpoint[i] + "/" + lstmax[i]);
                    //listView2.Items.Add(lstpoint[i] + "/" + lstmax[i]);
                }
            }
            catch (Exception)
            {
                //listView2.Items.Add(lstpoint[i] + "/" + lstmax[i]);
                d.SubItems.Add(lstpoint[i] + "/" + lstmax[i]);
            }
            d.SubItems.Add(datez[i]);
            d.SubItems.Add(lstav[i] + "/" + lstmax[i]);
            d.SubItems.Add(lstcomment[i]);
            listView1.Items.Add(d);
        }
        checkBox1.Text += "(" + min50.ToString() + ")";
        checkBox2.Text += "(" + max100.ToString() + ")";
        checkBox3.Text += "(" + eq50.ToString() + ")";

        pictureBox1.Visible = false;
        //groupBox1.Location = new Point(12, 12);
        checkBox5.Checked = false;


        button2.Enabled = true;
        checkBox1.Enabled = true;
        checkBox2.Enabled = true;
        checkBox3.Enabled = true;
        checkBox4.Enabled = true;
        checkBox5.Enabled = true;
        checkBox6.Enabled = true;
        shouldirefresh = true;
        label3.Text = DateTime.Now.ToString("dd/MM/yyyy hh:mm");


   }

如果我MessageBox.Show(lsttit[i]);它每次都显示正确的数据,我的ListView会有正确的列,并设置为详细信息,但根本没有任何事情发生....

这里有什么问题?

0 个答案:

没有答案