16,472
社区成员
发帖
与我相关
我的任务
分享
void CIrregularDlg::OnInsert()
{
int nm = m_LT1.GetSelCount();
if( nm < 1 ) return;//判断是否有内容选中
CArray< int,int > arySel;
arySel.SetSize( nm );
m_LT1.GetSelItems(nm, arySel.GetData()); //取得选中的所有项的序号
int k2Nm = m_LT2.GetCount();
for( int ik = 0; ik < nm; ik ++ )
{
CString IxTx;
m_LT1.GetText( arySel[ik], IxTx );//取得某一项的文本
m_LT2.InsertString(k2Nm,IxTx);//添加到右侧栏中
k2Nm++;//右侧序号加1
}
for( int ih = nm-1; ih > -1; ih-- ) //反向循环从左侧框中清理掉已经进入右侧框的内容
{
m_LT1.DeleteString(arySel[ih]);
}
int km = 0;
while(km < arySel.GetSize()) //清理CArray类型内存防止内存泄露
{
arySel.RemoveAt(km);
}
arySel.RemoveAll();
}
void CIrregularDlg::OnDelete()
{
int nm = m_LT2.GetSelCount();
if( nm < 1 ) return;
CArray< int,int > arySel;
arySel.SetSize( nm );
m_LT2.GetSelItems(nm, arySel.GetData());
int k2Nm = m_LT1.GetCount();
for( int ik = 0; ik < nm; ik ++ )
{
CString IxTx;
m_LT2.GetText( arySel[ik], IxTx );
m_LT1.InsertString(k2Nm,IxTx);
k2Nm++;
}
for( int ih = nm-1; ih > -1; ih-- )
{
m_LT2.DeleteString(arySel[ih]);
}
int km = 0;
while(km < arySel.GetSize())
{
arySel.RemoveAt(km);
}
arySel.RemoveAll();
}