Sunday, April 11, 2010

windows application Add Combobox in Gridview at run time

this method is use to bind table value in dataset;

public DataTable cmbBindGrid()
{
DataAccess da = new DataAccess();
DataSet ds = new DataSet();
try
{
ds = da.GetDataTable("SELECT MPId,MPName FROM MilkatParkarPK");
return ds.Tables[0];
}
catch (Exception ex) { return ds.Tables[0]; }
}

Then

private void namuna8_Load(object sender, EventArgs e)
{
DataGridViewComboBoxColumn x = new DataGridViewComboBoxColumn();
x.DataSource = cmbBindGrid();
x.DisplayMember = "MPName";
x.ValueMember = "MPId";
x.HeaderText = "ekyeRrspk Ádkj";
x.Name = "Test";
x.Visible = true;
x.Width = 170;
dataGridView1.Columns.Add(x);
}

No comments:

Post a Comment