Prem Sahani

Prem Sahani

  • NA
  • 123
  • 9.3k

DatagridviewComboboxColumns problem ...

Oct 9 2017 11:23 AM
Hello all my senior ,
 
select * from tblPremiseFacility where PremiseID = 'P-00001'

id code facility
1 P-00001 Play background
2 P-00001 Video Games 
 
that to value i want to show in datagridview combobox....
 
note : value should be direcotly  show in datagridview. no need to click and select..
 
i have written this code : only one value show but other one not  so kindly help 
 
DataSet ds = new DataSet();

string str = "P-00001";
cmd = new SqlCommand("select * from tblPremiseFacility where PremiseID ='" + str+"'", con);
da.SelectCommand = cmd;
da.Fill(ds);
//dataGridView3.DataSource = ds.Tables[0];

foreach (DataRow dr in ds.Tables[0].Rows)
{
for (int i = 0; i <= dataGridView3.Rows.Count - 1; i++)
{
if (dataGridView3.Rows != null)
{
this.dataGridView3.Rows[i].Cells["b"].Value = dr["facilities"].ToString();
this.dataGridView3.Rows[i].Cells["a"].Value = dr["PremiseID"].ToString();
b.DisplayStyleForCurrentCellOnly = true;

}
}

}
 
other code for retrieve the value in dgrcombobox ..i working
 
private void dis()
{
DataSet ds = new DataSet();

string str = "P-00001";
cmd = new SqlCommand("select PremiseID, facilities from tblPremiseFacility where PremiseID ='" + str + "'", con);
da.SelectCommand = cmd;
da.Fill(ds);

b.DataSource = ds.Tables[0];
b.DisplayMember = "facilities";
b.ValueMember = "facilities";
b.DefaultCellStyle.NullValue = "Choose a value";

}
 
thank to all

Answers (3)