怎么取CheckedListBox选中项的value值

yongchaochu 2010-04-29 10:07:52
//绑定数据源
DataTable table = service.GetProductListDogType(whereString);

this.checkedListBox1.DataSource = table;

this.checkedListBox1.ValueMember = "Id";

this.checkedListBox1.DisplayMember = "ProjName";
//使CheckListBox中所有项都被选中
for (int j = 0; j < this.checkedListBox1.Items.Count; j++)
{
this.checkedListBox1.SetItemChecked(j, true);
}
-----以上都是没有问题的 已经过我的测试
int length = this.checkedListBox1.CheckedItems.Count;
for (int i = 0; i < length; i++)
{
probreedInfo.BreedId =
Convert.ToInt32((this.checkedListBox1.CheckedItems[i].SelectedValue.ToString()));
//this.checkedListBox1.CheckedListBox[i].ValueMember.ToString();

}
以上两种方式都无法获取选中项的value值,提示不存在SelectedValue,ValueMember


哪位大侠帮帮忙
...全文
534 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cheery_an 2011-03-31
  • 打赏
  • 举报
回复
如需要阅读该回复,请登录或注册CSDN!
捷哥1999 2010-04-29
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 yongchaochu 的回复:]

int productId = Convert.ToInt32(lvProduct.SelectedItems[0].SubItems[0].Text.ToString());
probreedInfo.ProductId = productId;

int length = this.checked……
[/Quote]

不错,自己搞定问题,这就是进步呀!恭喜了,顺便接分了。呵呵。
yongchaochu 2010-04-29
  • 打赏
  • 举报
回复
int productId = Convert.ToInt32(lvProduct.SelectedItems[0].SubItems[0].Text.ToString());
probreedInfo.ProductId = productId;

int length = this.checkedListBox1.Items.Count;
for (int i = 0; i < length; i++)
{
if (this.checkedListBox1.GetItemChecked(i) == true)
{
probreedInfo.BreedId =Convert.ToInt32(table.Rows[i]["Id"]);


//ser.AddInfoIntoProductBreedMap(probreedInfo);
}

}
问题搞定
yuanhuiqiao 2010-04-29
  • 打赏
  • 举报
回复
用this.checkedListBox1.CheckedItemCollection,参考
xiaofan_sap 2010-04-29
  • 打赏
  • 举报
回复
你去前台source里看看 浏览器解析出来的名字是不是这个阿

111,092

社区成员

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

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

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