必须是Winform的
由于从来没有进行过Winform的开发,所以不知道从哪里入手。问题比较清晰,如下:
有一个产品列表需要放到ComboBox控件中,并且会在很多页面中出现。所以需要封装一个ComboBox控件,在控件内部进行数据局绑定,无需在调用的页面上进行数据源赋值操作(在其他页面直接拖过去就可以用了)。
假如控件的名字叫BrandComboBox
用下面的数据进行绑定 DataTable tempDt = new DataTable();
tempDt.Columns.Add("ItemText");
tempDt.Columns.Add("ItemValue");
for (int i = 0; i < 5; i++)
{
DataRow tempDr = tempDt.NewRow();
tempDr["ItemText"] = String.Format("{0}{0}{0}{0}", i);
tempDr["ItemValue"] = i.ToString();
tempDt.Rows.Add(tempDr);
}
由于从来没有进行过Winform的开发,所以不知道从哪里入手。问题比较清晰,如下:
有一个产品列表需要放到ComboBox控件中,并且会在很多页面中出现。所以需要封装一个ComboBox控件,在控件内部进行数据局绑定,无需在调用的页面上进行数据源赋值操作(在其他页面直接拖过去就可以用了)。
假如控件的名字叫BrandComboBox
用下面的数据进行绑定 DataTable tempDt = new DataTable();
tempDt.Columns.Add("ItemText");
tempDt.Columns.Add("ItemValue");
for (int i = 0; i < 5; i++)
{
DataRow tempDr = tempDt.NewRow();
tempDr["ItemText"] = String.Format("{0}{0}{0}{0}", i);
tempDr["ItemValue"] = i.ToString();
tempDt.Rows.Add(tempDr);
}
this.comboBox1.ValueMember = "作为值读取的字段或属性名";//Value
this.comboBox1.DataSource=数据源;
public MyComBase ()//构造函数绑定
{
}
this.comboBox1.ValueMember = "作为值读取的字段或属性名";//Value
this.comboBox1.DataSource=数据源;