checkedListBox怎样邦定隐藏值

lys1706228 2007-02-13 12:14:08
checkedListBox1.Items.Add(ds.Tables["Ro"].Rows[i]["RName"], false); 怎样邦定隐藏值,谢谢 就是RName的ID
...全文
240 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
3000sunqin 2007-02-13
  • 打赏
  • 举报
回复
flyaqiao(KiteReport(http://www.kitesoft.cn)) 不好意思,没有看到您的Format事件代码,所以您的方法应该是可以正常显示的。
3000sunqin 2007-02-13
  • 打赏
  • 举报
回复
flyaqiao(KiteReport(http://www.kitesoft.cn)) 的方法也不错,但是它在listBox中的显示有问题,ListBox中显示的是你添加的对象的ToString()函数的结果;
3000sunqin 2007-02-13
  • 打赏
  • 举报
回复
好象不能直接实现,但是你可以这样来实现
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 2007-02-13
  • 打赏
  • 举报
回复
可以直接绑定DataRow,通过Format事件.
这样SelectedItem里就是DataRow对象,你想要哪个字段都没有问题.
flyaqiao 2007-02-13
  • 打赏
  • 举报
回复
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();
}
「已注销」 2007-02-13
  • 打赏
  • 举报
回复
up
flyaqiao 2007-02-13
  • 打赏
  • 举报
回复
你可以使用Format事件,这样就不会是ToString()了.
best8625 2007-02-13
  • 打赏
  • 举报
回复
Array吧
lys1706228 2007-02-13
  • 打赏
  • 举报
回复
显示是没有问题,怎么能获取到,那些被选中了 private void checkedListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string id = (checkedListBox1.SelectedItem as DataRow)["Id"].ToString();
}

选中多个,这个id怎么存,谢谢!

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧