how to set value in DataGridViewComboBoxColumn from a datatable?
DataGridViewComboBoxColumn dgvcb = (DataGridViewComboBoxColumn)grvPackList.Columns["Units"];
开发者_运维问答 Globals.G_ProductUtility G_Utility = new Globals.G_ProductUtility();
dgvcb.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
G_Utility.addUnittoComboDGV(dgvcb);
DataSet _ds = iRawMaterialsRequest.Select();
grvPackList.DataSource = _ds.Tables[0];
the problem is that the DataGridViewComboBoxColumn in the datagrid is not selected with the value in table how is it possilbe to set value of DataGridViewComboBoxColumn from datasoure
int i=0;
foreach (DataRow dgvr in _ds.Tables[0].Rows )
{
grvPackList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
i++;
}
this code is working but is there any solution with out using loops?
int i=0;
foreach (DataRow dgvr in _ds.Tables[0].Rows )
{
grvPackList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
i++;
}
When i Tried this it worked fine
you can bind the DataGridViewComboBoxColumn directly to your datasouce like
DataGridViewComboBoxColumn dgvcb = (DataGridViewComboBoxColumn)grvPackList.Columns["Units"];
dgvcb.ValueMember = "YourUnitValue";
dgvcb.DisplayMember = "Units";
dgvcb.DataSource = _ds.Tables[0];
精彩评论