(方法一)
checkedListBox1.Items.Add(ds.Tables["Ro"].Rows[i], false);
private void checkedListBox1_Format(object sender, ListControlConvertEventArgs e)
{
e.Value = (e.ListItem as DataRow)["RName"].ToString();
}
private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string id = (checkedListBox1.SelectedItem as DataRow)["Id"].ToString();
}
(方法二)
public clsItemEntity
{
public string Name;
public string id;
public clsItemEntity(string strName,int intID)
{
this.Name = strName;
this.id = intID;
}
public override string ToString()
{
return this.Name;
}
}
在checkedListBox填充代码中
checkedListBox1.Items.Add(new("Name1",1),false) ;
checkedListBox1.Items.Add(new("Name2",2),false) ;
checkedListBox1.Items.Add(new("Name3",3),false) ;
要取数据时使用checkedListBox1.CheckedItems[]来引用被Checked的对象
然后将其强制转型为clsItemEntity就可以使用它的id属性了