我列出了从sqlite列存储解析数据的列表。我想在 listview 中向用户显示这些列表。他们单击一个按钮,列表视图(当前有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);
}
答案 0 :(得分:2)
您需要将ListViewItem
对象lvi
添加到Listview
以获取已填充的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());
}
ListView1.Items.Add(lvi);//here you need to add
}