向上/向下按钮未被禁用 [英] Up/down buttons not getting disabled

查看:87
本文介绍了向上/向下按钮未被禁用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表中有一些项目,当我在列表中选择一个项目并连续点击向上按钮仍然它到达顶部位置并且在其重新调整的顶部位置之后我的按钮应该被移除。

但是它的当我们点击顶部位置并点击了向上按钮后,没有解开和删除项目。

你可以帮助我吗



< b>我尝试了什么:



 onupbuutonclicked(){

int item2 = m_clist_ctl.GetNextItem( - 1 ,LVNI_SELECTED);
int columns = m_clist_ctl.GetHeaderCtrl() - > GetItemCount();
// 退出订单#column(0)
for int i = 1 ; i< columns ; i ++)
{
CString str1 = m_clist_ctl.GetItemText(item2 + 1 ,i);
CString str2 = m_clist_ctl.GetItemText(item2,i);
m_clist_ctl.SetItemText(item2 + 1 ,i,str2);
m_clist_ctl.SetItemText(item2,i,str1);

}
m_clist_ctl.SetItemState(item2,~LVNI_SELECTED,LVNI_SELECTED);
m_clist_ctl.SetItemState(item2 + 1 ,LVNI_SELECTED,LVNI_SELECTED);

}

OnLvnItemchangedList(NMHDR * pNMHDR,LRESULT * pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast< lpnmlistview>(pNMHDR);
// TODO:在此处添加您的控制通知处理程序代码
int count = m_clist_ctl.GetItemCount();
int row = m_clist_ctl.GetSelectionMark();
int lastRow = count - 1 ;
if (( 0 == count)||(row< 0 )){
GetDlgItem(IDC_BUTTON_UP) - > EnableWindow(FALSE);

}
其他 如果((count> = < span class =code-digit> 2 )&&(row> 0 )){
GetDlgItem(IDC_BUTTON_UP) - > EnableWindow(TRUE);
}
else {
GetDlgItem(IDC_BUTTON_UP) - > EnableWindow(FALSE);
}

}



如果我的代码中有任何错误,请告诉我

解决方法方案

原因是更改选择时不会调用 OnLvnItemchangedList 。通过在 onupbuutonclicked 中调用 SetItemText 来更改内容时调用它。但是当处理它时,选择仍然在旧位置并且按钮未被禁用。



所以你可以在<$ c $结束时禁用按钮c> onupbuutonclicked 当 item2 == 1 时(但看起来你发布的代码是按下按钮而不是按钮,因为你正在交换 item2 item2 + 1 )。



你也可以使用单个调用来启用/禁用 OnLvnItemchangedList 中的按钮:

 //当前选择不是第一个时启用按钮row 
//无需检查项目数,因为当> = 1
GetDlgItem(IDC_BUTTON_UP) - > EnableWindow(row> 0);

i have some items in list when i selected one item in list and clicked the up button continuosly still it reached top place and after its reched top place my up button should get disbaled.
but its not disbling and its deleting item when it recahes top place and after we clicked the up button.
could you please help me here

What I have tried:

onupbuutonclicked(){

 int item2 = m_clist_ctl.GetNextItem(-1, LVNI_SELECTED);
        int columns = m_clist_ctl.GetHeaderCtrl()->GetItemCount();
        //Leaving out the order# column(0)
        for (int i = 1; i < columns; i++)
        {
            CString str1 = m_clist_ctl.GetItemText(item2 + 1, i);
            CString str2 = m_clist_ctl.GetItemText(item2, i);
            m_clist_ctl.SetItemText(item2 + 1, i, str2);
            m_clist_ctl.SetItemText(item2, i, str1);
          
        }
        m_clist_ctl.SetItemState(item2, ~LVNI_SELECTED, LVNI_SELECTED);
        m_clist_ctl.SetItemState(item2 + 1, LVNI_SELECTED, LVNI_SELECTED);

}

OnLvnItemchangedList(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMLISTVIEW pNMLV = reinterpret_cast<lpnmlistview>(pNMHDR);
    // TODO: Add your control notification handler code here
    int count = m_clist_ctl.GetItemCount();
    int row = m_clist_ctl.GetSelectionMark();
    int lastRow = count - 1;
    if ((0 == count) || (row < 0)) {
 GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);

               }
   else if ((count >= 2) && (row > 0)) {
            GetDlgItem(IDC_BUTTON_UP)->EnableWindow(TRUE);
        }
        else {
            GetDlgItem(IDC_BUTTON_UP)->EnableWindow(FALSE);
        }

   }


could you please tell me if anything si wrong in my code

解决方案

The reason is that OnLvnItemchangedList is not called when changing the selection. It is called when changing the content by calling SetItemText in onupbuutonclicked. But when that is processed the selection is still on the old position and the button is not disabled.

So you might disable the button at the end of onupbuutonclicked when item2 == 1 (but it looks like your posted code is for button down instead of button up because you are exchanging item2 and item2+1).

You may also use a single call to enable / disable the button in OnLvnItemchangedList:

// Enable button when current selection is not first row
// No need to check item count because that is always >= 2 when row >= 1
GetDlgItem(IDC_BUTTON_UP)->EnableWindow(row > 0);


这篇关于向上/向下按钮未被禁用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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