C# CheckedListBox 中添加带 Text 和 Value 的 CheckBox

然后在代码中定义 DataTable,并和CheckedListBox 关联(CheckedListBox的名称为 receive):

DataTabledataTable =newDataTable();
dataTable.Columns.Add("Text",typeof(string));
dataTable.Columns.Add("Value",typeof(string));
this.receive.DataSource = dataTable;
this.receive.DisplayMember ="Text";
this.receive.ValueMember ="Value";

向DataTable中加入DataRow对象:

DataRowdataRow = dataTable.NewRow();
dataRow["Text"] = receive[1];
dataRow["Value"] = receive[0];
dataTable.Rows.Add(dataRow);