我有存储来自 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);
}