计时器关闭所有Listview项目

时间:2015-11-13 15:30:59

标签: c# windows-forms-designer

我的计时器正在勾选列表视图中的所有项目,但我希望它只做第一项。

我试过的是移除foreach循环,但它不会识别我的物品,这个小东西让我疯了!

这是我的代码:

private void ListViewTrainingQue()
{          
   listView1.View = View.Details;
   listView1.GridLines = true;
   listView1.FullRowSelect = true;

   string string2 = "https://api.eveonline.com/char/SkillQueue.xml.aspx?keyID=4602486&&vCODE=BHGVeXQkRLKLkIkZQHdeyUxmUz9EfUwbvGzoc2eO4ZR8kRMYxk8PbD4LMwLF7BvH";


    // Add Columns to listview 
    listView1.Columns.Add("Name", 50);
    listView1.Columns.Add("Level", 50);
    listView1.Columns.Add("Remaing Time", 100);
    listView1.Columns.Add("Bar", 100);

    // string array1 = "2015-10-23 13:00";

    // Create Array to return values to. 
    string[] arr = new string[3];

    XmlDocument XMLtrans = new XmlDocument();
    XMLtrans.Load(string2);
    XmlNodeList TRnodelist = XMLtrans.SelectNodes("/eveapi/result/rowset/row");
    foreach (XmlNode xmlnode in TRnodelist)
    {     
       string array1 = xmlnode.Attributes["endTime"].InnerText;
       var date1 = DateTime.Parse(array1);
       var Timespan = date1 - DateTime.Now;

       if (xmlnode.Attributes["typeID"] != null)
          arr[0] =  xmlnode.Attributes["typeID"].InnerText;
       if (xmlnode.Attributes["level"] != null)
          arr[1] = xmlnode.Attributes["level"].InnerText;
       if (xmlnode.Attributes["endTime"] != null)
          arr[2] = string.Format("{0}h {1}m {2}s", Timespan.Hours, Timespan.Minutes, Timespan.Seconds);

       var items = new ListViewItem(arr);
       items.Tag = date1;
       listView1.Items.Add(items);
    }
} 

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
}

public void timer1_Tick(object sender, EventArgs e)
{
   foreach (ListViewItem items in listView1.Items)
   {
      var timeSpan = ((DateTime)items.Tag) - DateTime.Now;
      items.SubItems[2].Text = string.Format("{0}h {1}m {2}s", timeSpan.Hours, timeSpan.Minutes, timeSpan.Seconds);                
   }
}

0 个答案:

没有答案