• CListCtrl 添加新行后把新行设为选中高亮,删除某行,把某行下一行选中高亮


    添加一行后,设为选中高亮

    m_nindex = m_list.GetItemCount() -1 ;
    m_list.SetItemState(m_nindex , LVIS_SELECTED, LVIS_SELECTED );

    删除某行后,把某行的下一行选中高亮

    void CDlgSysManager::OnBnClickedButtonDelete()
    {
    if ( m_list.GetItemCount() <2)
    {
    MessageBox( "can't delete last user", MB_OK );
    return ;
    }

    DLGDeleteEnter dlg;
    POSITION pos=m_list.GetFirstSelectedItemPosition();
    if (pos)
    {
    if (IDOK == dlg.DoModal( ))
    {
    int index=m_list.GetNextSelectedItem(pos);//得到选中的行号,
    m_nindex = index ;
    if ( m_nindex == m_list.GetItemCount() -1)
    {
    m_nindex = index - 1;
    }
    deleteuser( index );

    }
    }
    else
    {
    if (IDOK == dlg.DoModal( ))
    {
    int n = m_nindex;
    if ( m_nindex == m_list.GetItemCount() - 1)//加入要删除的是最后一行,删除后最后一行行号要减1
    {
    m_nindex -= 1;
    }
    deleteuser( n );
    }
    }

    void CDlgSysManager::deleteuser(int nindex)
    {
    CUser *pUser=( CUser * )m_list.GetItemData( nindex );//通过这个行号而取得内容的对象(指针);
    if (pUser)
    {
    POSITION postemp=m_Usermap.Find(pUser);
    if (postemp)
    {
    if (theApp.m_adoConn.ExecuteNoSelectSQL(pUser->GetDeleteSQL()))
    {
    m_Usermap.RemoveAt(postemp);
    FillAllUerList();
    ShowUserinfo();
    }
    }
    }
    delete pUser;
    pUser = NULL;
    m_list.SetItemState(m_nindex , LVIS_SELECTED, LVIS_SELECTED );
    }

  • 相关阅读:
    如何打开肉鸡的3389端口(xp的)
    XP鲜为人知的实用技巧(一)
    利用Ms08067工具进行溢出攻击
    教你建一个别人看不到打不开的文件夹
    在IE上显示自己的名字
    QQ使用的七大非常规秘籍
    第五篇:Python函数基础篇
    Centos7之Systemd(Service文件)详解
    Linux GCC make文件的写法3
    DSP/BIOS学习笔记——2.SWI
  • 原文地址:https://www.cnblogs.com/chenzuoyou/p/3110653.html
Copyright © 2020-2023  润新知