给DataGridView中 DataGridViewComboBoxColumn列赋值
我在DataGridView添加了一列DataGridViewComboBoxColumn列名units,为其建立一个模板public class classComboData
{
private string m_display = string.Empty;
private string m_value = string.Empty;
public classComboData(string display, string value)
{
this.m_display = display;
this.m_value = value;
}
public string Display
{
get { return this.m_display; }
set { this.m_display = value; }
}
public string Value
{
get { return this.m_value; }
set { this.m_value = value; }
}
}
//读取配置文件,取得所有的单位名称和其ID号
XmlNodeList unitName = mainfrm.class_ReadxmlDB.GetNodeList((int)classReadXML.AllXMLFile.unitsName);
if (unitName != null && unitName.Count > 0)
{
DataGridViewComboBoxCell cellSex = new DataGridViewComboBoxCell();
for (int i = 0; i < unitName.Count; i++)
{
string displayName = unitName.Item(i).Attributes["UnitName"].Value.ToString();
string displayValue = unitName.Item(i).Attributes["ID"].Value.ToString();
//将单位名称添加到DataGridViewComboBoxCell
cellSex.Items.Add(new classComboData(displayName, displayValue));
}
cellSex.DisplayMember = "Display";
cellSex.ValueMember = "Value";
units.CellTemplate = cellSex; //设置列DataGridViewComboBoxColumn列名units的模板
unitName = null;
}
怎样再窗体加载时设置此列的默认值?
请各位帮帮忙!!!!!!!!!!!!!!