删除按钮出现问题 [英] Problem with delete button

查看:96
本文介绍了删除按钮出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我的英语不好

我创建了一个简单的项目.我的程序从本地计算机加载了一些图像,并将其显示在列表控件中.如果用户在列表控件中选择图像,我会添加一个删除按钮以删除图像.

但是当我选择1张以上的图像时,删除按钮消失了.有人帮我吗?

非常感谢.
[更新]
这是我处理事件的方式.但是当我按下Control键并选择1张以上图片时,删除按钮消失了

void OnBnClickedBtnDeleteBase()
{
    // TODO: Add your control notification handler code here
     int msgboxID = MessageBox(
        L"Do you want to delete selected image?",
        L"Delete image",
        MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
    switch (msgboxID)
    {
        case IDYES:
            // TODO: add code
            DeleteSeletedBase();
            break;
        case IDNO:
            // TODO: add code
            break;
    }
}



[更新]

对不起!问题不在上层代码中.

问题在这里:

 如果(pNMListView-> uNewState& LVIS_SELECTED)
    {
        m_btnDeleteBase.EnableWindow(TRUE);
    }
    其他
        m_btnDeleteBase.EnableWindow(FALSE); 



所以任何人都可以告诉我,如何选择多个项目:(.我不太擅长c ++

Anhybody知道iItem变量:(它有用吗?我试过了,但没有任何反应:(

[另一个更新]
如果您使用
崩溃

  if ((pNMListView-> uNewState& LVIS_SELECTED)||(pNMListView-> uNewState& LVIS_FOCUSED))
    {
        m_btnDeleteBase.EnableWindow(TRUE);
    } 



您可以选择1个以上的项目.但是在某些情况下,删除"按钮仍处于禁用状态. :(有人帮我吗?

解决方案

您是否拥有样式LVS_SINGLESEL?如果是,则将其删除以具有多种选择.

接下来,使用GetSelectedCount()获取列表中所选项目的数量.如果不为零,请使用GetFirstSelectedItemPosition()GetNextSelectedItem()遍历所选项目.


  if (pNMListView-> GetSelectedCount>  0 )
{
    m_btnDeleteBase.EnableWindow(TRUE);
}

// 或简单地
m_btnDeleteBase.EnableWindow(pNMListView-> GetSelectedCount>  0 ); 


我想如果只删除重点项目,用户会感到困惑.每当选择状态的变化,检查有任何选择,如果你.


的NMLISTVIEW仅仅是一个通知消息的结构.您要在关联的列表控件上调用GetSelectedCount .如果您正在使用CListView控件调用CListView::GetListCtrl ,然后在返回的对象上调用CListCtrl::GetSelectedCount .

http://msdn.microsoft.com/en-us/library/7sdaafak(VS .80).aspx [ ^ ]

请尝试上面的链接以获取更多参考.


Sorry for my poor English

I have created a simple project. My program load some image from my local computer and display it in a list control. I add a delete button to delete image if user choose an image in list control.

But when I choose more than 1 image, delete button is disappeared. Anybody help me?

Thanks a lot.
[Update]
Here is the way I handle event. But when I press control and choose more than 1 image, delete button is disappeared

void OnBnClickedBtnDeleteBase()
{
    // TODO: Add your control notification handler code here
     int msgboxID = MessageBox(
        L"Do you want to delete selected image?",
        L"Delete image",
        MB_ICONWARNING | MB_YESNO | MB_DEFBUTTON2);
    switch (msgboxID)
    {
        case IDYES:
            // TODO: add code
            DeleteSeletedBase();
            break;
        case IDNO:
            // TODO: add code
            break;
    }
}



[Update]

Sorry! Problem is not in the upper code.

The problem is here:

if( pNMListView->uNewState & LVIS_SELECTED )
    {
        m_btnDeleteBase.EnableWindow(TRUE);
    }
    else
        m_btnDeleteBase.EnableWindow(FALSE);



So anybody can tell me, how can I choose multiple item :(. I am not very good at c++

Anhybody know about iItem variable :( is it useful? I tried but nothing happens :(

[Another update]
If you use
Collapse

if( (pNMListView->uNewState & LVIS_SELECTED) || (pNMListView->uNewState & LVIS_FOCUSED))
    {
        m_btnDeleteBase.EnableWindow(TRUE);
    }



You can choose more than 1 items. But in some cases, delete button is still disable Frown | :( Anybody help me?

解决方案

Do you have the style LVS_SINGLESEL? If yes, then remove it to have multiple selections.

Next, use GetSelectedCount() to get the number of items selected in the list. If non-zero, loop through the selected items using GetFirstSelectedItemPosition() and GetNextSelectedItem().


if (pNMListView->GetSelectedCount > 0)
{
    m_btnDeleteBase.EnableWindow(TRUE);
}

// Or simply
m_btnDeleteBase.EnableWindow(pNMListView->GetSelectedCount > 0);


I suppose the user would be confused if only the focused item was deleted. Whenever the selection state changes, check if you have any selection.


The NMLISTVIEW is just a notification message structure. You want to call GetSelectedCount on the associated list control. If you''re using a CListView control call CListView::GetListCtrl then call CListCtrl::GetSelectedCount on the returned object.

http://msdn.microsoft.com/en-us/library/7sdaafak(VS.80).aspx[^]

Try above link for further reference.


这篇关于删除按钮出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆