private void frmShowData_Load(object sender, EventArgs e) { Text = "显示数据"; this.tabControl1.TabIndex = 0; dt = ClassTable.getDataTable("d:/data.txt"); #region 采用listView显示数据 this.listView1.View = View.Details;//条目列表形式为详细列表 listView1.Columns.Add("时间", 200, HorizontalAlignment.Left); listView1.Columns.Add("温度", 150, HorizontalAlignment.Left); listView1.Columns.Add("湿度", 100, HorizontalAlignment.Left); ListViewItem item; for (int i = 0; i < dt.Rows.Count; i++) { item = new ListViewItem(new string[] { dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString(), dt.Rows[i][2].ToString() }); listView1.Items.Add(item); } #endregion #region 采用datagridview显示数据 this.dataGridView1.DataSource = dt; #endregion }