本文介绍了如何设置的SelectedIndex在DataGridViewComboBoxColumn?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用一个DataGridView在我使用的是datagridviewcomboboxcolumn,comboboxcolumn是显示文本,但问题是我想在默认情况下选择comboboxcolumn的第一项我怎么能做到这一点。
DataGridViewComboBoxColumn dgvcb =(DataGridViewComboBoxColumn)grvPackingList.Columns [PackingUnits];
Globals.G_ProductUtility G_Utility =新Globals.G_ProductUtility();
G_Utility.addUnittoComboDGV(dgvcb);
的DataSet _ds = iRawMaterialsRequest.SelectBMR(bmr_ID,branch_ID,包装);
grvPackingList.DataSource = _ds.Tables [0];
INT I = 0;
的foreach(DataRow的dgvr在_ds.Tables [0] .Rows)
{
grvPackingList.Rows [I] .Cells [单位。值= dgvr [单位。的ToString();
I ++;
}
解决方案
在下拉列表中可用的值可以通过项目属性访问
row.Cells [col.Name] .value的=(row.Cells [col.Name]如的DataGridViewComboBoxCell).Items [0];
i am using a datagridview in that i am using a datagridviewcomboboxcolumn, comboboxcolumn is displaying text but the problem is i want to select the first item of comboboxcolumn by default how can i do this
DataGridViewComboBoxColumn dgvcb = (DataGridViewComboBoxColumn)grvPackingList.Columns["PackingUnits"];
Globals.G_ProductUtility G_Utility = new Globals.G_ProductUtility();
G_Utility.addUnittoComboDGV(dgvcb);
DataSet _ds = iRawMaterialsRequest.SelectBMR(bmr_ID, branch_ID, "PACKING");
grvPackingList.DataSource = _ds.Tables[0];
int i = 0;
foreach (DataRow dgvr in _ds.Tables[0].Rows)
{
grvPackingList.Rows[i].Cells["Units"].Value = dgvr["Units"].ToString();
i++;
}
解决方案
The values available in the combobox can be accessed via items property
row.Cells[col.Name].Value = (row.Cells[col.Name] as DataGridViewComboBoxCell).Items[0];
这篇关于如何设置的SelectedIndex在DataGridViewComboBoxColumn?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!