Solved

How do u find string in a CListCtrl?

Posted on 1998-07-17
7
652 Views
Last Modified: 2013-11-20
Hi guys, my question is how to do a search ( similar to SelectString in CListBox )
on a CListCtrl on the SECOND column ? This is becuase the FindItem member does not
have a column index parameter where I can specify which column to search for the string?
Pls. give an example if possible... :)
Thanks!!!!

David Chong
0
Comment
Question by:Haho
  • 3
  • 3
7 Comments
 
LVL 1

Expert Comment

by:atari
ID: 1319419
Look at http://codeguru.com/listview/listview_toc.shtml. There are so many examples for using a CListCtrl that there must be a solution for your problem.

Bye,
atari
0
 
LVL 1

Expert Comment

by:atari
ID: 1319420
I want to add something to the above answer:
Maybe you could use GetItemText() instead of FindItem() something like this:


CString s,search_string="Whatever you want to search";
for (int i=0;i<yourlistCtrl.GetItemCount();i++)
{
 s=GetItemText(i,column);
 if (s==search_string)
 {
    AfxMessageBox("I have found it");
    break;
  }
}

But some other examples you find in the sorting-section of the above web-site.

Bye,
atari
0
 
LVL 1

Author Comment

by:Haho
ID: 1319421
thanks atari but the above coding solutiuon does not seem very efficient becuase my program will search through quite a huge list ( 1000+ ) and it might be slow...
I am trying to find any MFC methods that will do the same job ( eg. FindItem ) but the (speed) performance must not be compromised.... :) Any ideas? Thanks a lot, guys

David Chong
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Expert Comment

by:chacko
ID: 1319422
Use the same FindItem function. The flag member LVFI_PARAM can be added along with other parameters to first member of LV_FINDINFO. Then cast a LV_ITEM object to lParam which is the third parameter in LV_FINDINFO struct.
0
 
LVL 1

Author Comment

by:Haho
ID: 1319423
Hi chacko,
   I have looked at the LV_FINDINFO structure but I am not sure what values to set.
If I have not forgotten, there is a index and a subindex field of the structure... can u give me a simple example ( take the second column to be searched )?? Thanks..  
right now I am setting it to LVFI_PARTIAL which is no good cause it searches the first column.

David Chong
0
 
LVL 1

Accepted Solution

by:
atari earned 70 total points
ID: 1319424
Second try:

This might help you for setting the correct parameters of LV_FINDINFO-structure:


int CMyGridList::FindItemData(DWORD dwItemData)
// --- In  : dwItemData : Original data to search for
// --- Out :
// --- Returns : The index of the item that has this original data associated with it
// --- Effect : This functions calls the underlying window procedure directly
//                      instead of sending a message
{
  ASSERT(::IsWindow(m_hWnd));
  LV_FINDINFO lvfi;
  memset(&lvfi, 0, sizeof(LV_FINDINFO));
  lvfi.flags = LVFI_PARAM;
  lvfi.lParam = (LPARAM)dwItemData;
  return (int) DefWindowProc(LVM_FINDITEM, (WPARAM)-1, (LPARAM)&lvfi);
}

I didn't know, that you have such a lot of items.
Bye,
atari
0
 
LVL 1

Author Comment

by:Haho
ID: 1319425
atari,

  Thanks for your help. I will go through your example ( and try to implement it )...
anyway, I have tested the first solution u gave me and the speed is acceptable , the only
worse thing is that my sorting ( on the second column ) using a custom function (recurvise sorting) is taking bout 4 seconds while the searching is less than or about a second...
so the problem here can be considered solved... the challenge now is to reduce my sorting time... !!! Bye.. :)

Have a nice day
David Chong


0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now