1. C++常用代码总结(2)

本文介绍了一个使用ListCtrl控件的应用程序中单击和双击事件的具体实现方式。通过重载函数,当用户与ListCtrl交互时,可以获取选中的条目信息,并在双击时进一步处理如确认删除等操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 
//ListCtrl控件单击事件,重载函数
void CContentsSubmitDlg::OnNMClickList1(NMHDR *pNMHDR, LRESULT *pResult)
{
         POSITION   pos=m_ListResult.GetFirstSelectedItemPosition();
         CString content;
         CString employee;
         CString schedua;
         CString datetime;
         int nItem;
         if(pos!=NULL)  
         {  
              while(pos)  
              {   nItem=m_ListResult.GetNextSelectedItem(pos);
                   content=m_ListResult.GetItemText(nItem,0);
                   schedua=m_ListResult.GetItemText(nItem,1);
                   datetime=m_ListResult.GetItemText(nItem,2);
                   employee=m_ListResult.GetItemText(nItem,3);
              }
              GetDlgItem(IDC_EDIT4)->SetWindowText(content);
              GetDlgItem(IDC_EDIT5)->SetWindowText(schedua);
              GetDlgItem(IDC_EDIT7)->SetWindowText(datetime);
         }
         *pResult = 0;
     }
//ListCtrl控件双击事件
void CContentsSubmitDlg::OnNMDblclkList1(NMHDR *pNMHDR, LRESULT *pResult)
     {
     //   CString s="您双击了选择项";
     //   AfxMessageBox(s);
         CString aa=(( CContentsSubmitApp *)AfxGetApp())->namelogin;
         aa.TrimLeft(" ");     
         aa.TrimRight("     ");
         aa.TrimRight(" ");
         aa.TrimRight(" ");
         aa.TrimRight("/t");
         POSITION   pos=m_ListResult.GetFirstSelectedItemPosition();
         CString content;
         CString employee;
          int nItem;
         if(pos!=NULL)  
         {  
               while(pos)  
               {    nItem=m_ListResult.GetNextSelectedItem(pos);
      content=m_ListResult.GetItemText(nItem,0); employee=m_ListResult.GetItemText(nItem,3);
               }
 if(employee!=aa)
     { AfxMessageBox("您不能删除别人的提报内容?",MB_OK);         return;            }
      else
      {   ADOconn m_conn;   _bstr_t vSQL="";
 CString s_Conn="Provider=SQLOLEDB;Server=10.128.128.221;Database=Eink;uid=stone;pwd=stone";
 vSQL="delete contens where workcontents='"+content+"' and employee='"+employee+"'";
         try
         { m_conn.OnInitADOConn(s_Conn);
          UINT YORN=AfxMessageBox("您确认删除该记录吗?",MB_YESNO);
          if(YORN==IDYES)
         {    m_conn.ExcuteSQL(vSQL);             }
         else {             return;               }
          }
          catch(...)
          {       AfxMessageBox("数据库删除错误",MB_OK);                 }
         AfxMessageBox("数据成功删除",MB_OK);
         m_ListResult.DeleteItem(nItem);
         }        }
         *pResult = 0;
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值