我在填充listview的时候,错把listview.clear()当做listview.item.clear()来使用了,结果listview中什么都没有了。
代码如下:
private void acceptorFull()
{
string sql = "select * from mails where isdeleted=1";
FullListview(sql);
}
private void FullListview(string sql)
{
SqlCommand cmd = new SqlCommand(sql,DBHelper.conn);
try
{
DBHelper.conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
listView1.Clear();//这里本来应该是listView1.Items.Clear();的
while (dr.Read())
{
int id=(int)dr["id"];
MessageBox.Show(id.ToString());
ListViewItem lviMail = new ListViewItem(id.ToString());
lviMail.Tag = id;
listView1.Items.Add(lviMail);
lviMail.SubItems.AddRange(new string[] { dr["receiver"].ToString(), dr["acceptor"].ToString(), dr["date"].ToString(), dr["remark"].ToString() });
}
dr.Close();
}
慕尼黑8549860
回首忆惘然