This is my code
private void Attendance_Load(object sender, EventArgs e) { WindowState = FormWindowState.Maximized; dtp_INTime.Value = DateTime.Now; dtp_INTime.Format = DateTimePickerFormat.Custom; dtp_INTime.CustomFormat = "dd-MMM-yyyy hh:mm"; dtp_INTime.MaxDate = DateTime.Now; dtp_OUTTime.Value = DateTime.Now; dtp_OUTTime.Format = DateTimePickerFormat.Custom; dtp_OUTTime.CustomFormat = "dd-MMM-yyyy hh:mm"; dtp_OUTTime.MaxDate = DateTime.Now; dataGridView1.AutoGenerateColumns = false; dataGridView1.AllowUserToAddRows = false; Binddata(); }
private void Binddata()
{
con.Close();
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("select * from tbl_AttecndanceCheck", con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader() ;
dt.Load(dr);
dataGridView1.AutoGenerateColumns = false;
//dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns[1].DataPropertyName = dt.Columns[0].ToString();
dataGridView1.Columns[2].DataPropertyName = dt.Columns[1].ToString();
dataGridView1.Columns[3].DataPropertyName = dt.Columns[2].ToString();
if(dt.Rows.Count>0)
{
for (int i = 1; i < dt.Rows.Count; i++)
{
if (Convert.ToBoolean(dt.Rows[i]["Status"]) == true)
{
MessageBox.Show("Hai");
DataGridViewCheckBoxCell ch1 = new DataGridViewCheckBoxCell();
ch1 = (DataGridViewCheckBoxCell)dataGridView1.Rows[i].Cells[7];
ch1.Selected = true;
// dataGridView1.Rows[i].Cells["Status"].Value = true;
//dataGridView1.Rows[i].Cells["Status"].Value = true;
//this.dataGridView1.Rows[i].Cells[7].Value ="True";
//dataGridView1.Rows[i].Cells[7].Value = 1;
}
}
}
dataGridView1.DataSource = dt;
Aucun commentaire:
Enregistrer un commentaire