Solved

How do u find string in a CListCtrl?

Posted on 1998-07-17
7
676 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to know only "File created" with EventLog 3 35
string initialization in java 11 117
FizzBuzz challenge 9 85
Excel file not created as expected 7 94
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 …
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…
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.

726 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