Click here to Skip to main content
15,891,375 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a view named "FamilyView" to join 2 tables(Families and SStatus) and replace an id in the first table(Families) by its name existing in the second table(SStatus) (the column is now called "Status")

This view is now displayed in a datagridview that the user can modify

Sda = new SqlDataAdapter("Select * from FamilyView",con);
Sda.Fill(ds);
dg.DataSource = ds.Tables[0];
dg.Refresh();

What i want is to transform the column cells "Status" to comboboxes containing all Names from SStatus

SqlDataAdapter sadapter = new SqlDataAdapter("Select * From SStatus", con);
DataSet ds1 = new DataSet();
sadapter.Fill(ds1);

i found this code:

DataGridViewComboBoxCell ComboColumn = (DataGridViewComboBoxCell)(dg.Rows[i].Cells[0]);
ComboColumn.DataSource = ds1.Tables[0];
ComboColumn.DisplayMember = "Name";

but i can't replace the cell

and this code but I'm not sure how to use it:

Adding bound combobox to datagridview

BindingSource StatusBD = new BindingSource();
StatusBD.DataSource = ds1;


DataGridViewComboBoxColumn colType = new DataGridViewComboBoxColumn();
colType.HeaderText = "Status";
colType.DropDownWidth = 90;
colType.Width = 90;
//colType.DataPropertyName = "Name";
colType.DataSource = ds;
colType.DisplayMember = "Name";
colType.ValueMember = "IdStatus";

dg.Columns.Insert(dg.Columns.GetColumnCount(DataGridViewElementStates.None) - 1, colType);
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900