hi
i am using combobox to bind the datagridview and i am created a comboboxcolumn
in datagridview .everytime if i selected different value from combox it will
recreate the another new comboboxcolumn. i set autogeneratecolumn=false. stillnot working and my code is
try
{
SqlConnection con = new SqlConnection("data source = localhost\\SQLEXPRESS;initial catalog = mgrsch_schools; integrated security = true");
con.Open();
string s = "select * from hmloading1 ";
string s2 = "select *from teacherdetailloading where sub1='"+comboBox1.Text+"' ";
DataSet ds = new DataSet();
SqlDataAdapter dd = new SqlDataAdapter(s, con);
SqlDataAdapter dd1 = new SqlDataAdapter(s2, con);
SqlCommandBuilder cmb1 = new SqlCommandBuilder(dd);
SqlCommandBuilder cmb2 = new SqlCommandBuilder(dd1);
dd.Fill(ds, "hmloading1");
dd1.Fill(ds, "teacherdetailloading");
SqlCommand cmd = new SqlCommand(s, con);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.AutoGenerateColumns = false;
this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque;
this.dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;
dataGridView1.Columns["slno"].Visible = false;
}
DataGridViewComboBoxColumn cmb = new DataGridViewComboBoxColumn();
cmb.HeaderText = "Prekg";
cmb.Name = "cmb";
cmb.DataSource = ds.Tables["teacherdetailloading"];
cmb.DisplayMember = "name";
cmb.ValueMember = "name";
dataGridView1.Columns.Add(cmb);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.AutoGenerateColumns = false;
DataGridViewComboBoxColumn comb1 = new DataGridViewComboBoxColumn();
comb1.HeaderText = "Lkg";
comb1.Name = "comb1";
comb1.DataSource = ds.Tables["teacherdetailloading"];
comb1.DisplayMember = "name";
comb1.ValueMember = "name";
dataGridView1.Columns.Add(comb1);
dataGridView1.DataSource = ds.Tables[0];
dataGridView1.AutoGenerateColumns = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
}
i write this code in comboxselected indexchange event.
if anyone have any idea helpme.