[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do u find string in a CListCtrl?

Posted on 1998-07-17
7
Medium Priority
?
712 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 210 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

829 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