• 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 );
    }

  • 相关阅读:
    mysql 存在该记录则更新,不存在则插入的sql
    php计划任务的实现
    Dictionary<TKey,TValue>泛型封装
    win10家庭版 获取 syswow64权限
    发送带参数post请求
    visual studio自动向量化
    交叉编译
    opencv笔记meanshift&camshift
    [源码学习]调试Razor从哪里开始
    [转]官网下载Google Chrome离线安装包
  • 原文地址:https://www.cnblogs.com/chenzuoyou/p/3110653.html
Copyright © 2020-2023  润新知