Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How do u find string in a CListCtrl?

Posted on 1998-07-17
7
Medium Priority
?
703 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
In this post we will learn different types of Android Layout and some basics of an Android App.
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

618 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