Click here to Skip to main content
15,903,388 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C#
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
C++
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?
Posted
Updated 30-Mar-11 20:53pm
v6
Comments
Sergey Alexandrovich Kryukov 28-Mar-11 0:31am    
Nobody can tell you anything unless you show some relevant code.
--SA

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().
 
Share this answer
 
Comments
Lương Thông Đạt 28-Mar-11 1:25am    
I already done in Delete() function and I don't have LVS_SINGLESEL.
I think when I use "pNMListView->uNewState & LVIS_SELECTED" it does not allow to choose multiple items so it run else clause. In requirement of my project, delete button is available when user choose one or more than one items.
C++
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.
 
Share this answer
 
Comments
Lương Thông Đạt 28-Mar-11 22:23pm    
:( pNMListView is an object of NMLISTVIEW, attribute GetSelectedCount is not belong to it. Can you tell me how to make count selected item?
Niklas L 29-Mar-11 2:34am    
You do have access to the CListCtrl somewhere. If it is a CListView, use CListView::GetListCtrl() as hansen described, and if it is a CListCtrl in a dialog of CFormView, just add a variable for it, or access it with GetDlgItem(IDC_MYLIST_WHATEVER).
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.
 
Share this answer
 
v2
Comments
[no name] 29-Mar-11 1:55am    
Good Link.
Lương Thông Đạt 29-Mar-11 3:23am    
Thanks for your support :D I did it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900