本文实例讲述了C#实现ComboBox控件显示出多个数据源属性的方法。分享给大家供大家参考。具体如下:
public partial class Form4 : Form{ private Bitmap myBitmap; public Form4() { InitializeComponent(); DataTable dt = new DataTable(); DataColumn dc1 = new DataColumn("Name", typeof(System.String)); DataColumn dc2 = new DataColumn("Age", typeof(System.String)); dt.Columns.Add(dc1); dt.Columns.Add(dc2); for (int i = 0; i < 20; i++) { DataRow row = dt.NewRow(); row["Name"] = i.ToString(); row["Age"] = i.ToString(); dt.Rows.Add(row); } comboBox1.DataSource = dt; } private void comboBox1_Format(object sender, ListControlConvertEventArgs e) { DataRowView myDataRowView = (DataRowView)(e.ListItem); e.Value = string.Format("{0}-{1}-{2}", myDataRowView["Name"], myDataRowView["Name"], myDataRowView["Name"]); }}
希望本文所述对大家的C#程序设计有所帮助。
新闻热点
疑难解答