GetSelectedCount意想不到的问题

m45m46 2013-05-03 08:11:50
如果不对Clistctrl做选择item操作的话,GetSelectedCount的返回值接近列表中item总数的一半,例如
如果item总数为18,那么GetSelectedCount的返回值为9;
如果item总数为19,那么GetSelectedCount的返回值为10;
有哪位大侠能解救小弟啊!!!
...全文
202 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
向立天 2013-07-02
  • 打赏
  • 举报
回复
您好 我是本版版主 此帖已多日无人关注 请您及时结帖 如您认为问题没有解决可按无满意结帖处理 另外本版设置了疑难问题汇总帖 并已在版面置顶 相关规定其帖子中有说明 您可以根据规定提交您帖子的链接 如您目前不想结帖只需回帖说明 我们会删除此结帖通知 见此回复三日内无回应 我们将强制结帖 相关规定详见界面界面版关于版主结帖工作的具体办法
schlafenhamster 2013-05-18
  • 打赏
  • 举报
回复
vc6 xp 上: // delete void CTransListCtrlDlg::OnButton1() { int itemselectednum=m_TransListCtrl.GetSelectedCount(); afxDump << itemselectednum << "\n"; int itemnum1=m_TransListCtrl.GetItemCount(); afxDump << itemnum1 << "\n"; int i; for (i=itemnum1-1;i>=0;i--) { if (m_TransListCtrl.GetItemState(i,LVIS_SELECTED)==LVIS_SELECTED) { afxDump << "Item " << i << " will be deleted!\n"; //m_TransListCtrl.DeleteItem(i); } } if( i<0 ) afxDump << "No item has been deleted!\n"; } 没问题!
m45m46 2013-05-16
  • 打赏
  • 举报
回复
8l,我看见别人是从后往前删,不过我这样写居然也没错; 9l,if (iselected!=0)和if (iselected==LVIS_SELECTED)效果一样; 上述问题是执行int itemselectednum=m_list_imagecarrier.GetSelectedCount()这句出现问题的,我调试过了,当不选择任何一个item时,执行到这一句时,itemselectednum的值有错;而当选择一个item时,itemselectednum的值又是正常的。
菜牛 2013-05-08
  • 打赏
  • 举报
回复
删除列表控件里的项,要从后往前删。
schlafenhamster 2013-05-08
  • 打赏
  • 举报
回复
if (iselected!=0) 错了 f (iselected==LVIS_SELECTED)
m45m46 2013-05-07
  • 打赏
  • 举报
回复
楼上的是什么意思?
百合杰 2013-05-04
  • 打赏
  • 举报
回复
代码贴上来先
向立天 2013-05-04
  • 打赏
  • 举报
回复
这不可能啊 你具体怎么操作的
见习学术士 2013-05-04
  • 打赏
  • 举报
回复
不会吧,那你用个循环获取一下看看
schlafenhamster 2013-05-04
  • 打赏
  • 举报
回复
if (iselected==LVIS_SELECTED) LVIS_SELECTED=2;
m45m46 2013-05-04
  • 打赏
  • 举报
回复

不选择列表中的某一行而直接点“删除载体图像”按钮的话,列表中就自动删除一半的行,效果如图
m45m46 2013-05-04
  • 打赏
  • 举报
回复
删除列表中的item函数

void CDataHidingDlg::OnButtonDeleteimage()
{
// TODO: Add your control notification handler code here
int i,iselected;
int itemselectednum=m_list_imagecarrier.GetSelectedCount();
int itemnum1=m_list_imagecarrier.GetItemCount();
if (itemselectednum<1)
{
AfxMessageBox("请选择要删除的载体图像。");
return;
}
for (i=0;i<itemnum1;i++)
{
iselected=m_list_imagecarrier.GetItemState(i,LVIS_SELECTED);
if (iselected!=0)
m_list_imagecarrier.DeleteItem(i);
}
int itemnum2=m_list_imagecarrier.GetItemCount();
for (i=0;i<itemnum2;i++)
{
char ichar [25];
itoa(i+1,ichar,10);
m_list_imagecarrier.SetItemText(i,0,ichar);
}
}
上面的函数是“删除载体图像”按钮的函数,本来这个按钮是首先在列表中选择一行,然后点这个按钮就删除这一行了,这个功能是没问题,但是如果你不选择列表中的某一行而直接点“删除载体图像”按钮的话,列表中就自动删除一半的行,也就是如上图,只剩下3行了,我调试了一下,是函数GetSelectedCount的返回值出现问题。

15,979

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 界面
社区管理员
  • 界面
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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