checkedListBox怎样邦定隐藏值 checkedListBox1.Items.Add(ds.Tables["Ro"].Rows[i]["RName"], false); 怎样邦定隐藏值,谢谢 就是RName的ID 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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(); } 可以直接绑定DataRow,通过Format事件.这样SelectedItem里就是DataRow对象,你想要哪个字段都没有问题. 好象不能直接实现,但是你可以这样来实现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属性了 flyaqiao(KiteReport(http://www.kitesoft.cn)) 的方法也不错,但是它在listBox中的显示有问题,ListBox中显示的是你添加的对象的ToString()函数的结果; flyaqiao(KiteReport(http://www.kitesoft.cn)) 不好意思,没有看到您的Format事件代码,所以您的方法应该是可以正常显示的。 显示是没有问题,怎么能获取到,那些被选中了 private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e) { string id = (checkedListBox1.SelectedItem as DataRow)["Id"].ToString(); }选中多个,这个id怎么存,谢谢! 你可以使用Format事件,这样就不会是ToString()了. linq里面orderby是怎么排序的,稳定吗,效率是多少有没有人知道 求救Cache问题,在线等候,请高手帮帮忙 能不能在C#程序,里面调用Spy++ 请问如何实现Windows编辑菜单的功能 C# 序列号 如何把值传进弹出框 请教这个问题 急!!! 要启用实时(JIT)调试 cs操作类里面如何应用Server.MapPath? 又一个MDI的问题 mysql语句 如何将查出来的字符串转化为数字.用的phpmyadmin Microsoft.Rtc.Sip.UnauthorizedException类型的异常,100分 C# WinForm怎么做或画一个表格状的履历表格?
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();
}
这样SelectedItem里就是DataRow对象,你想要哪个字段都没有问题.
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属性了
{
string id = (checkedListBox1.SelectedItem as DataRow)["Id"].ToString();
}选中多个,这个id怎么存,谢谢!