Dear All
I have 7 columns of yes/no data type I want to show them in datagridview in checkbox form. I have written this code where I am showing some values from database to datagridview with a column having check box. I just want to show databse value in Under Sun,Mon,Tue,Wed,Thr,Fri,Sat columns Please refer the code
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.Rows.Clear();
int no_of_branch=0;
int batch_count;
int totalbatch = 0;
foreach (var checkBoxSele in grpBox1.Controls.OfType<CheckBox>().OrderBy(m => m.Name))
{
no_of_branch++;
}
string[] str = new string[no_of_branch];
no_of_branch=0;
foreach (var checkBoxSele in grpBox1.Controls.OfType<CheckBox>().OrderBy(m => m.Name))
{
if (checkBoxSele.Checked)
{
str[no_of_branch] = checkBoxSele.Text;
MessageBox.Show(str[no_of_branch]);
no_of_branch++;
}
}
for (int j = 0; j < no_of_branch; j++)
{
try
{
aCommand3 = new OleDbCommand("select * from batch_tbl where batch_branch LIKE '" + str[j] + "'", main_connection);
aAdapter3 = new OleDbDataAdapter(aCommand3);
ds3 = new DataSet();
aAdapter3.Fill(ds3, "app_info");
batch_count = ds3.Tables[0].Rows.Count;
dataGridView1.ColumnCount = 11;
dataGridView1.Columns[0].Name = "Batch Code";
dataGridView1.Columns[1].Name = "Centre";
dataGridView1.Columns[2].Name = "Duration";
dataGridView1.Columns[3].Name = "Time";
dataGridView1.Columns[4].Name = "Sun";
dataGridView1.Columns[5].Name = "Mon";
dataGridView1.Columns[6].Name = "Tue";
dataGridView1.Columns[7].Name = "Wed";
dataGridView1.Columns[8].Name = "Thr";
dataGridView1.Columns[9].Name = "Fri";
dataGridView1.Columns[10].Name = "Sat";
for (int k = 0; k < batch_count; k++)
{
string exisBatch = ds3.Tables[0].Rows[k][0].ToString();
int batlen = exisBatch.Length;
string dur = ds3.Tables[0].Rows[k][16].ToString();
DateTime vtime = DateTime.Parse("16:00");
switch (dur)
{
case "Mor": vtime = DateTime.Parse("08:00");
break;
case "Eve": vtime = DateTime.Parse("16:00");
break;
}
shortBCode = ds3.Tables[0].Rows[k][1].ToString() + ds3.Tables[0].Rows[k][15].ToString() + ds3.Tables[0].Rows[k][16].ToString().Substring(0, 1) + exisBatch.Substring(batlen - 3);
dataGridView1.Rows.Add(shortBCode,
ds3.Tables[0].Rows[k][2].ToString(),
ds3.Tables[0].Rows[k][10].ToString(),
vtime.ToString("HH:mm"),
ds3.Tables[0].Rows[k][7].ToString());
//comboBox2.Items.Add(ds3.Tables[0].Rows[i][0].ToString());
totalbatch++;
}
dataGridView1.Columns[0].ReadOnly = true;
dataGridView1.Columns[1].ReadOnly = true;
DataGridViewCheckBoxColumn chk = new DataGridViewCheckBoxColumn();
dataGridView1.Columns.Add(chk);
chk.HeaderText = "Freeze";
chk.Name = "chk";
label3.Text = totalbatch.ToString();
}
catch (OleDbException ex)
{
MessageBox.Show("Please close the Databse");
}
}
}