private void checkXueyaInfo_Load(object sender, EventArgs e) { dataGridView1.ColumnHeadersDefaultCellStyle.Font = new System.Drawing.Font("微软雅黑", 12, System.Drawing.FontStyle.Regular); this.dataGridView1.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill; //让默认的日期时间减一天 this.dateTimePicker1.Value = this.dateTimePicker2.Value.AddDays(-1); DataTable dtbichao = tjdao.checkXueyaInfo(dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss"), null, basicInfoSettings.xcuncode); //DataTable dtbichao = tjdao.checkXueyaInfo(basicInfoSettings.createtime, null, basicInfoSettings.xcuncode); if (dtbichao != null && dtbichao.Rows.Count > 0) { this.dataGridView1.DataSource = dtbichao; this.dataGridView1.Columns[0].HeaderCell.Value = "体检时间"; this.dataGridView1.Columns[1].HeaderCell.Value = "姓名"; this.dataGridView1.Columns[2].HeaderCell.Value = "档案编号"; this.dataGridView1.Columns[3].HeaderCell.Value = "身份证号"; this.dataGridView1.Columns[4].HeaderCell.Value = "条码号"; this.dataGridView1.Columns[5].HeaderCell.Value = "是否检验"; this.dataGridView1.Columns[0].Width = 120; this.dataGridView1.Columns[1].Width = 120; this.dataGridView1.Columns[2].Width = 160; this.dataGridView1.Columns[3].Width = 160; this.dataGridView1.Columns[4].Width = 110; this.dataGridView1.Columns[5].Width = 100; this.dataGridView1.RowsDefaultCellStyle.ForeColor = Color.Black; this.dataGridView1.AllowUserToAddRows = false; int rows = this.dataGridView1.Rows.Count - 1 <= 0 ? 0 : this.dataGridView1.Rows.Count - 1; for (int x = 0; x <= rows; x++) { this.dataGridView1.Rows[x].HeaderCell.Value = String.Format("{0}", x + 1); } } else { this.dataGridView1.DataSource = null; } }