Solved

How do u find string in a CListCtrl?

Posted on 1998-07-17
7
656 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 62
Creating Labels and Frequency list style reports in SAS code 9 92
Expand macro to ask for filename column 8 37
FizzBuzz challenge 9 76
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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 demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

914 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

18 Experts available now in Live!

Get 1:1 Help Now