ArrayList mylist = new ArrayList();
mylist.Add(new DictionaryEntry(“0”, “请选择”));
cb.ValueMember = “Key”;
cb.DisplayMember = “Value”;
cb.DataSource = mylist;
说明绑定的是DictionaryEntry 而不是DictionaryEntry的value
((DictionaryEntry)list.Items[e.Index]).Value.ToString()
///
/// 修改comboBox中值高度
///
///
///
public static void cmbBind(ComboBox list, int itemHeight)
{
list.DropDownStyle = ComboBoxStyle.DropDownList;
list.ItemHeight = itemHeight;
list.DrawMode = DrawMode.OwnerDrawFixed;
list.DrawItem += new DrawItemEventHandler(delegate (object sender, DrawItemEventArgs e)
{
if (e.Index < 0)
{
return;
}
e.DrawBackground();
e.DrawFocusRectangle();
e.Graphics.DrawString(((DictionaryEntry)list.Items[e.Index]).Value.ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);
});
}
//调用方式
cmbBind(this.cobroomCode, 20);