如何在CListCtrl中查找指定项
1个回答
展开全部
可以实现,曾写过类似的程序;(m_list为CListCtrl,sFind_name为EDIT框关联CString)
LRESULT CBOOKView::OnFind(WPARAM wParam, LPARAM lParam)
{
int flag =0;
for(int i=0; i<m_list.GetItemCount(); i++)
{
if((!sFind_name.IsEmpty())&&strstr(m_list.GetItemText(i,0),sFind_name.GetBuffer(strlen(sFind_name))))
{
m_list.SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
flag = 1;
}
}
for( i=0; i<m_list.GetItemCount(); i++)
{
if((!sFind_email.IsEmpty())&&strstr(m_list.GetItemText(i,1),sFind_email.GetBuffer(strlen(sFind_email))))
{
m_list.SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
flag = 1;
}
}
if(flag==0)MessageBox("没找到!!!!");
return 0;
}
LRESULT CBOOKView::OnFind(WPARAM wParam, LPARAM lParam)
{
int flag =0;
for(int i=0; i<m_list.GetItemCount(); i++)
{
if((!sFind_name.IsEmpty())&&strstr(m_list.GetItemText(i,0),sFind_name.GetBuffer(strlen(sFind_name))))
{
m_list.SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
flag = 1;
}
}
for( i=0; i<m_list.GetItemCount(); i++)
{
if((!sFind_email.IsEmpty())&&strstr(m_list.GetItemText(i,1),sFind_email.GetBuffer(strlen(sFind_email))))
{
m_list.SetItemState(i, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED);
flag = 1;
}
}
if(flag==0)MessageBox("没找到!!!!");
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询