public void LoadDiscount()
{
List<Discount> listdiscount = new List<Discount>();
listdiscount.Insert(0, new Discount() { discount = 0, DiscountName = "免费" });
listdiscount.Insert(1, new Discount() { discount = 0.1f, DiscountName = "一折" });
listdiscount.Insert(2, new Discount() { discount = 0.2f, DiscountName = "二折" });
listdiscount.Insert(3, new Discount() { discount = 0.3f, DiscountName = "三折" });
listdiscount.Insert(4, new Discount() { discount = 0.4f, DiscountName = "四折" });
listdiscount.Insert(5, new Discount() { discount = 0.5f, DiscountName = "五折" });
listdiscount.Insert(6, new Discount() { discount = 0.6f, DiscountName = "六折" });
listdiscount.Insert(7, new Discount() { discount = 0.7f, DiscountName = "七折" });
listdiscount.Insert(8, new Discount() { discount = 0.8f, DiscountName = "八折" });
listdiscount.Insert(9, new Discount() { discount = 0.9f, DiscountName = "九折" });
listdiscount.Insert(10, new Discount() { discount = 1, DiscountName = "不打折" });
CmbDiscount.DataSource = listdiscount;
CmbDiscount.DisplayMember = "discount";
CmbDiscount.ValueMember = "DiscountName";
}
这样用不行吗
我想将打折与中文的联系起来
public struct Discount
{
public float discount;
public string DiscountName;
}
定义了个结构体来装这两种数据
我打断点看是DataSource是有值
------解决思路----------------------
用dataTable就好了 建2列放两个参数 按行加入你的11个数据
------解决思路----------------------
属性没有get;set; 例如,
public float discount;
public float DisCount{
get{return discount;}
set{discount = value;}
}
------解决思路----------------------
Combox绑定字体、图片成员示例
private void btn_Begin_Click(object sender, EventArgs e)
{
btn_Begin.Enabled = false;//停用开始按钮
cbox_DisplayPictures.DrawMode = DrawMode.OwnerDrawFixed;//设置绘制元素方式
cbox_DisplayPictures.DropDownStyle = //设置组合框样式
ComboBoxStyle.DropDownList;//codego.net/11/1/1/
cbox_DisplayPictures.Items.Add("自行车");//添加项
cbox_DisplayPictures.Items.Add("面包车");//添加项
cbox_DisplayPictures.Items.Add("修理工具");//添加项
cbox_DisplayPictures.Items.Add("人物");//添加项
G_ImageList = new ImageList();//创建ImageList对象
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.a);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.b);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.c);//添加图片
G_ImageList.Images.Add(global::PicturesInComboBox.Properties.Resources.d);//添加图片
}