checkedListBox怎样邦定隐藏值
checkedListBox1.Items.Add(ds.Tables[ "Ro "].Rows[i][ "RName "], false); 怎样邦定隐藏值,谢谢 就是RName的ID
------解决方案--------------------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属性了