这是我第一次尝试在列表视图中显示我的表信息。这是我到目前为止所做的,我无法弄清楚它为什么不起作用。我没有收到任何错误,列表视图在运行时仍然是空白。
listView1.Columns.Add("User", 100, HorizontalAlignment.Left);
listView1.Columns.Add("Name", 100, HorizontalAlignment.Center);
listView1.Columns.Add("Message", 382, HorizontalAlignment.Left);
listView1.Columns.Add("Date/Time", 100, HorizontalAlignment.Left);
listView1.View = View.Details;
SqlConnection sqlConnection = new SqlConnection("ConnectionInfo");
sqlConnection.Open();
SqlDataAdapter ada = new SqlDataAdapter("select * FROM MPCS.MEYER_BOARD WHERE BOARD_NAME = '" + cmbgroup.Text + "'", sqlConnection);
DataTable dt = new DataTable();
ada.Fill(dt);
for (int i = 0; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
ListViewItem listitem = new ListViewItem(dr["EMPLOYEE_ID"].ToString());
listitem.SubItems.Add(dr["POST_DATE"].ToString());
listitem.SubItems.Add(dr["BOARD_NAME"].ToString());
listitem.SubItems.Add(dr["MESSAGE_TEXT"].ToString());
listView1.Items.AddRange(new ListViewItem[] {listitem});
}