0

我有存储来自 sqlite 列的解析数据的列表。我想在列表视图中向用户显示这些列表。他们单击一个按钮,列表视图(当前有 3 列)应该显示这 3 个列表及其内容。

问题:我单击按钮,列表视图没有填充任何内容。什么也没有发生

我是编程新手..所以这是我的代码:

private void button7_Click(object sender, EventArgs e)
{
   ListViewItem lvi = new ListViewItem(); 
   foreach (object o in MaxLen)
   {
      lvi.SubItems.Add(o.ToString());
   }
   foreach (object a in SeqIrregularities)
   {
      lvi.SubItems.Add(a.ToString()); 
   }
   foreach (object b in PercentPopList)
   {
      lvi.SubItems.Add(b.ToString()); 
   }
}

附带说明一下,如果有人想看看我实际上是如何填充我的列表的,它就在这里:

string sql4 = "SELECT * FROM abc";
SQLiteCommand command = new SQLiteCommand(sql4, sqlite_conn);

// The datareader allows us to read the table abc row by row
SQLiteDataReader reader = command.ExecuteReader();

while (reader.Read())
{
   // Parse Seq column
   int seq;
   if (int.TryParse(reader["Seq"].ToString(), out seq))
      if (seq > 30)
      {
         SeqIrregularities.Add(seq);
         seq1 = true;
      }

   // Parse Max Length Column
   int maxlen;
   if (int.TryParse(reader["MaxLen"].ToString(), out maxlen))
      if (maxlen > 30.00)
      {
         MaxLen.Add(maxlen);
         maxlen1 = true;
      }

   // Parse % Populated Column 
   int PercentPop;
   if (int.TryParse(reader["Percnt"].ToString(), out PercentPop))
      if(PercentPop == 0 || PercentPop > 100 || PercentPop < 80) // decimals?
      {
         PercentPopList.Add(PercentPop);
      }
4

1 回答 1

2

您需要添加ListViewItem对象lviListview获取 Populated 3 List 的

private void button7_Click(object sender, EventArgs e)
{
   ListViewItem lvi = new ListViewItem(); 
   foreach (object o in MaxLen)
   {
      lvi.SubItems.Add(o.ToString());
   }

   foreach (object a in SeqIrregularities)
   {
      lvi.SubItems.Add(a.ToString()); 
   }
   foreach (object b in PercentPopList)
   {
      lvi.SubItems.Add(b.ToString()); 
   }

ListView1.Items.Add(lvi);//here you need to add
}
于 2013-11-14T18:35:32.490 回答