用过CheckedListBox的朋友请帮忙??

hxuan 2005-04-01 11:02:39
CheckedListBox1.DataSource=table.DefaultView;
CheckedListBox1.DisplayMember="sName";
CheckedListBox1.ValueMember="id";
如何把在checkedlistbox1中选中的选项添加到listbox1中
...全文
117 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunnydde 2005-04-01
  • 打赏
  • 举报
回复
for(int i = 0 ; i< checkedListBox1.Items.Count;i++)
{
if(checkedListBox1.GetItemChecked(i))
{
listBox1.Items.Add(((DataRowView)checkedListBox1.Items[i])["sName"].ToString());
}
}
sunnydde 2005-04-01
  • 打赏
  • 举报
回复
暂时不知道什么好方法..下面这段代码你复制去看看能用不. 字段名我给你改了
DataTable dt = new DataTable();
dt.Columns.Add("sName");
dt.Columns.Add("id");

for(int i = 0 ; i < checkedListBox1.Items.Count ; i++)
{
if(checkedListBox1.GetItemChecked(i))
{
DataRow dr = dt.NewRow();
dr["sName"]=((DataRowView)checkedListBox1.Items[i])["sName"].ToString();
dr["id"]=((DataRowView)checkedListBox1.Items[i])["id"].ToString();
dt.Rows.Add(dr);
}
}
listBox1.DataSource=dt;
listBox1.ValueMember="id";
listBox1.DisplayMember="sName";
hxuan 2005-04-01
  • 打赏
  • 举报
回复
把listBox1.Items.Add(((DataRowView)checkedListBox1.Items[i])["sName"].ToString());
listBox1.Items.Add(((DataRowView)checkedListBox1.Items[i])["id"].ToString());
都添加到listbox1中去
sunnydde 2005-04-01
  • 打赏
  • 举报
回复
把你选中的item对象转成一个datarowview对象 之后根据字段来取就是了.
sunnydde 2005-04-01
  • 打赏
  • 举报
回复
把listBox1.Items.Add(((DataRowView)checkedListBox1.Items[i])["sName"].ToString());
里的["sName"]换成["id"]就可以了。
hxuan 2005-04-01
  • 打赏
  • 举报
回复
可能把CheckedListBox1.ValueMember="id";
也添加到listbox1中去呢?

111,125

社区成员

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

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

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