CListBoxはlist行の上下シフトを実現
5971 ワード
1.関数
2.実現方法
//
void GetAllTypeNameAndCheckStatus(std::mapint >& mapTypeNameCheckStatus);
// ( )
void SetAllTypeNameAndCheckStatus(std::mapint >& mapTypeNameCheckStatus, int nSelect);
// ——
afx_msg void OnBnClickedBtnUp();
// ——
afx_msg void OnBnClickedBtnDown();
2.実現方法
void CTunnelMaterialContentDlg::GetAllTypeNameAndCheckStatus(std::mapint >& mapTypeNameCheckStatus)
{
m_aryStuffName.RemoveAll();
for (int i = 0; i < m_stuffCheckList.GetCount(); i++)
{
CString strName;
int nChecked = 0;
m_stuffCheckList.GetText(i, strName);
nChecked = m_stuffCheckList.GetCheck(i);
m_aryStuffName.Add(strName);
mapTypeNameCheckStatus.insert(std::make_pair(strName, nChecked));
}
}
void CTunnelMaterialContentDlg::SetAllTypeNameAndCheckStatus(std::mapint >& mapTypeNameCheckStatus, int nSelect)
{
m_stuffCheckList.ResetContent();
for (int i = 0; i < m_aryStuffName.GetCount(); i++)
{
m_stuffCheckList.InsertString(i, m_aryStuffName.GetAt(i));
std::mapint >::iterator iter;
for (iter = mapTypeNameCheckStatus.begin(); iter != mapTypeNameCheckStatus.end(); iter++)
{
if ( (iter->first).CompareNoCase(m_aryStuffName.GetAt(i)) == 0 )
{
m_stuffCheckList.SetCheck(i, iter->second);
break;
}
}
}
m_stuffCheckList.SetCurSel(nSelect);
}
void CTunnelMaterialContentDlg::OnBnClickedBtnUp()
{
int nItem= m_stuffCheckList.GetCurSel();
if (nItem <= 0 || nItem > (m_stuffCheckList.GetCount() - 1) )
{
return;
}
std::mapint > mapTypeNameCheckStatus;
GetAllTypeNameAndCheckStatus(mapTypeNameCheckStatus);
CString strCurName;
m_stuffCheckList.GetText(nItem, strCurName);
for (int i = 0; i < m_aryStuffName.GetCount(); i++)
{
if (strCurName.CompareNoCase(m_aryStuffName.GetAt(i)) == 0)
{
m_aryStuffName.SetAt(i, m_aryStuffName.GetAt(i - 1));
m_aryStuffName.SetAt(i -1, strCurName);
break;
}
}
SetAllTypeNameAndCheckStatus(mapTypeNameCheckStatus, nItem - 1);
}
void CTunnelMaterialContentDlg::OnBnClickedBtnDown()
{
int nItem= m_stuffCheckList.GetCurSel();
if ( nItem >= (m_stuffCheckList.GetCount() - 1) || nItem < 0)
{
return;
}
std::mapint > mapTypeNameCheckStatus;
GetAllTypeNameAndCheckStatus(mapTypeNameCheckStatus);
CString strCurName;
m_stuffCheckList.GetText(nItem, strCurName);
for (int i = 0; i < m_aryStuffName.GetCount(); i++)
{
if (strCurName.CompareNoCase(m_aryStuffName.GetAt(i)) == 0)
{
m_aryStuffName.SetAt(i, m_aryStuffName.GetAt(i + 1));
m_aryStuffName.SetAt(i + 1, strCurName);
break;
}
}
SetAllTypeNameAndCheckStatus(mapTypeNameCheckStatus, nItem + 1);
}