Unable to use CListCtrl.FindItem after CListCtrl.SortItems

I have a CListCtrl which I want to sort, but after I sort I can no longer 
use FindItem because it always returns a failure.  Any assistance with this 
is greatly appreciated.

Thanks! 


0
dotygame (6)
3/13/2005 1:43:37 AM
vc.mfc 33608 articles. 0 followers. Follow

11 Replies
1821 Views

Similar Articles

[PageSpeed] 31

>I have a CListCtrl which I want to sort, but after I sort I can no longer 
>use FindItem because it always returns a failure.  Any assistance with this 
>is greatly appreciated.

Show a concise code example of what you're doing then someone may be
able to point out what's wrong.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
3/13/2005 10:16:33 AM
LVFINDINFO findinfo;

findinfo.flags=LVFI_STRING;

findinfo.psz=info->HostName;

CListCtrl myDevices;

<populate list control>

index=myDevices.FindItem(&findinfo, -1);

<find succeeds every time>

Now, add Sorting to the mix...
void myFunc::OnLvnColumnclickDevices(NMHDR *pNMHDR, LRESULT *pResult)

{

LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

myDevices.SortItems(MyCompareProc, pNMLV->iSubItem);

*pResult = 0;

}

The sort succeeds for every column that I click on.

Next I call find again...

index=myDevices.FindItem(&findinfo, -1);

Result:  index=-1;  <FAILED>

Hope this helps to figure out the problem...

Thanks!


"David Lowndes" <davidl@example.invalid> wrote in message 
news:3m483110oq174v6b1a93rp5m8t2dravi41@4ax.com...
> >I have a CListCtrl which I want to sort, but after I sort I can no longer
>>use FindItem because it always returns a failure.  Any assistance with 
>>this
>>is greatly appreciated.
>
> Show a concise code example of what you're doing then someone may be
> able to point out what's wrong.
>
> Dave
> -- 
> MVP VC++ FAQ: http://www.mvps.org/vcfaq 


0
dotygame (6)
3/13/2005 3:41:06 PM
What does your sort function look like? 


0
xxxx4922 (9)
3/13/2005 6:54:20 PM
int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM 
lParamSort)

{

// lParamSort contains a pointer to the list view control.

CListCtrl* pListCtrl = (CListCtrl*) ((lvData*)lParam1)->lCtrl;

LVFINDINFO findinfo;

findinfo.flags=LVFI_PARAM;

findinfo.lParam=lParam1;

int item1=pListCtrl->FindItem(&findinfo, -1);

findinfo.lParam=lParam2;

int item2=pListCtrl->FindItem(&findinfo, -1);

CString strItem1 = pListCtrl->GetItemText(item1, lParamSort);

CString strItem2 = pListCtrl->GetItemText(item2, lParamSort);

return strcmp(strItem2, strItem1);

}

"Craig S." <xxxx@ms.com> wrote in message 
news:O8TQa4$JFHA.3484@TK2MSFTNGP12.phx.gbl...
> What does your sort function look like?
> 


0
dotygame (6)
3/13/2005 10:07:23 PM
The comment:

> // lParamSort contains a pointer to the list view control.

does not apply.  This was part of the original code which didn't work. 
lParamSort is actually the column number.

Thanks,

Rob

"dotygr" <dotygame@rochester.rr.com> wrote in message 
news:%23ZAAJkBKFHA.3340@TK2MSFTNGP14.phx.gbl...
> int CALLBACK MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM 
> lParamSort)
>
> {
>
> // lParamSort contains a pointer to the list view control.
>
> CListCtrl* pListCtrl = (CListCtrl*) ((lvData*)lParam1)->lCtrl;
>
> LVFINDINFO findinfo;
>
> findinfo.flags=LVFI_PARAM;
>
> findinfo.lParam=lParam1;
>
> int item1=pListCtrl->FindItem(&findinfo, -1);
>
> findinfo.lParam=lParam2;
>
> int item2=pListCtrl->FindItem(&findinfo, -1);
>
> CString strItem1 = pListCtrl->GetItemText(item1, lParamSort);
>
> CString strItem2 = pListCtrl->GetItemText(item2, lParamSort);
>
> return strcmp(strItem2, strItem1);
>
> }
>
> "Craig S." <xxxx@ms.com> wrote in message 
> news:O8TQa4$JFHA.3484@TK2MSFTNGP12.phx.gbl...
>> What does your sort function look like?
>>
>
> 


0
dotygame (6)
3/13/2005 10:10:56 PM
Since the list view control passes the values to the sort callback function, 
lParam1 and lParam2 will conatin the lParam data of the two list view items 
being compared and lParamSort will contain the value passed to the function.

You are getting your CListCtrl* pointer from lParam1.  This means that every 
items data must contain a pointer to your CListCtrl and of course this would 
always  be the same value.

Craig 


0
xxxx4922 (9)
3/13/2005 11:31:27 PM
The sort function is working properly.  I have a structure, details below, 
which is different for each item which allows the sort to work.  My problem 
is that after the sort completes, every call to FindItem for the ClistCtrl 
fails.

Structure Info:
typedef struct lvData

{

LPVOID info;  //pointer to data structure which passes between program 
threads

LPVOID lCtrl;  //pointer to CListCtrl

bool isActive;

} *lv_Data;

"Craig S." <xxxx@ms.com> wrote in message 
news:elcyMTCKFHA.2212@TK2MSFTNGP12.phx.gbl...
> Since the list view control passes the values to the sort callback 
> function, lParam1 and lParam2 will conatin the lParam data of the two list 
> view items being compared and lParamSort will contain the value passed to 
> the function.
>
> You are getting your CListCtrl* pointer from lParam1.  This means that 
> every items data must contain a pointer to your CListCtrl and of course 
> this would always  be the same value.
>
> Craig
> 


0
dotygame (6)
3/13/2005 11:56:36 PM
// (CListCtrl*) ((lvData*)lParam1)->lCtrl;
oh sorry, didn't see the ->




0
xxxx4922 (9)
3/14/2005 1:06:56 AM
>>LVFINDINFO findinfo;
>>findinfo.flags=LVFI_STRING;
>>findinfo.psz=info->HostName;

The second time you call find.. are all these values still correct?  Is 
info->HostName still a valid string contained in your list view control? 


0
xxxx4922 (9)
3/14/2005 1:16:38 AM
After I execute the SortItems, the values are still valid and are definitely 
in the list.   After some thought, I realized that only calls to FindItem 
are failing when doing a find on the Text Value, but are succeeding when 
subsequent calls to my compare routine during SortItems which makes use of 
FindItem too (on the LPARAM).



0
dotygame (6)
3/14/2005 1:40:35 AM
>Hope this helps to figure out the problem...

You need to come up with a more complete example, something someone
can paste into a simple framework (say an MFC dialog app with a list
control on it) to reproduce your problem.

Dave
0
davidl7375 (2060)
3/14/2005 10:00:39 AM
Reply:

Similar Artilces:

How do I cut and paste using a macro....
Hello. I'm having trouble creating a macro that will let me cut postcodes from one cell and paste into another cell. I would appreciate if anybody can help me. What I have, is a large excel spreadsheet with a couple of thousand names and addresses. The address fields start in column B through to G. Each line of the address should be in a separate cell within each row, but the postcodes have all ended up in the same cell as the last line of the address. I need to cut the postcodes out of these cells and paste them into column H which is empty. The addresses are different lengths, leavi...

Unable to open Outlook2003. Error: MAPI unable loading msncon.dll
I am trying to set up Outlook 2003 on home computer but keep getting the following message when trying to open application. MAPI was unable to load the information service msncon.dll. Since I am not open to open, I cannot get to the help feature. Please advise Have you downloaded the latest MSN Connector from their site? Or, if not using it, have you uninstalled it? Try opening Outlook in Safe mode (start->run->outlook.exe /safe) and go into the Advanced options and uncheck it from add-in manager or COM add-ins. --� Milly Staples [MVP - Outlook] Post all replies to the group to ...

Using Money 98 in a virtual PC
I have used Money 98 for a good many years and am attached to it. It has run in 98, 2000, and XP without a hitch. I now have a 64 bit Windows 7 machine with a virtual PC installed which operates on XP as its operating system. I have my Money 98 installed there, but in that environment it runs with glacial slowness and I don't know why. All of the other apps I have in that VPC run just fine. I did notice that instead of using My Money.mny it uses My Money XP.mny. I can't imagine why that would cause slowing. Can anyone tell me where to look for answers? Thanks In microsoft....

Using Autocorrect to remove spaces
Hi, I am looking at how to remove extra spaces, and have been thinking about using Autocorrect. I have been reading another thread which suggested; For Each cell In Selection cell.Value = WorksheetFunction.Trim(cell.Text) Next What I have been using is; With Application.AutoCorrect .AddReplacement "Want", "Replace" End With Works well within a loop changing any "Replace" text with "Want". Something I didn't get Substitute to do correctly within a loop. What I can't get AutoCorrect to do though is work with spaces, so...

Unable to Edit/Add records on Form in a New ADP
I just started playing around with rebuilding a MDB file as an ADP. I built a form and subform from scratch, but I'm unable to edit or add records. SELECT Id, LoadDate, TrailerDOTNumber, SealNumber, SealDate, SealId, LoadLocation, LoadStatus, DispatchStatus, DispatchLocationId, DispatchUserId FROM TrailerActivityHeaders ORDER BY LoadDate Recordset Type: Updatable Snapshot I'm getting the 'This recordset is not updatable' Ideas? Never mind... (Does anyone have a spare bandage btw? I cut my head banging it on the wall due to my stupidity...) "D...

Unable to open calendar
Folks, i cannot open or view my calendar. When I start Oultook a Pop Up appears saying "Could not read the Calendar" On clicking Ok, the pop up vanishes and nothing happens. If i then go over to my calendar, it says "Cannot display the folder" I have run Oultook Diagnostics and nothing shows up as irregular. I ran the repair function (off my setuo CD) and nothing happened. I also re-installed Outlook and rebooted my comp and nada. When staring in safe mode i also get he same errors. I am using Off 2007, Win 7 TIA, P "phamiltonsmith" <...

unable to download emails and unable to stop synchronization
I am going to try one more time to get this fixed. My Outlook 2003 has been unable to download emails. While it is trying, a small box in the tray section shows up and it states that it is trying to synchronize folders. After a time out time Outlook gives me errors. This is the error message. It has these numbers 0X800CCC15 , or 0X8004210A, or 0X8004210B, which these error messages state that either I did not have enough timeout or look and see if server name is wrong. All of you have given me these suggestions. no joy. Thank you very much however. I went ahead and finally found a sect...

using for-next index in range variable
MSDN seems to say that range values must be written in the A1 format. I need to compare a value in column D (sample IDs) of worksheet import and compare it to column A (location) of worksheet data. If the values are equal I need to set a cell in worksheet data equal to the sum of columns I:M in the same row that the sample ID = the location. Will something like this work: If worksheet(import).cell[D"i"] = worksheet(data).cell[A"j"] then worksheet(data).cell[k,j] = sum(worksheet(import).[I"i":M"i"] Is there a different, perhaps easier way to do this? ...

Error sending email from Order using template
I created an email template to be used to confirm receipt of an order. It copies a few fields from the Order Form. It does not work, but shows a really helpful error message: MS CRM Web Page Dialog -An error has occurred; please consult your SA. Well, that's me. But I have no clue where to look. The built-in Order Thank You template shows the same behavior: Error. I made lots of email templates to be used from the Opportunity and Quote forms; these all work fine. I tried switching on tracing on the client (don't want to mess with the server registry keys) so I would get some ad...

using embedded .xsd vs file based .xsd
I am thinking of embedding my schemas as embedded resources instead of reading it using URI at run-time. I came across some snags while trying to do just that such as, previously unknown to me, XmlValidatingReader.Schemas.Add was using XmlValidatingReader.Resolver to resolve my schemas using the URI method. Resolver property was never set, so the reader simply ignored any external references even though one of the schema explicitly imports the other one. I verified this by removing the referred schema from the schema collection, and the code chugged along fine. But when I changed the code to ...

how can I use my e-mail addresses on excel xp with microsoft outlo #2
I need to use my addresses on Excel xp with Microsoft outlook. I want to use my excel file as a database that I can change and improve everyday. I need to send mails to more than 1 contact, so creating an e.mail link is not enough for me: in fact, if I click on it, I send my mail only to 1 address... Txs ...

Which shapes should be used?
I'm trying to draw a diagram which shows that an application is using odbc to access SQL Server database. I want to know which shapes I should use to represent the application, odbc, and SQL Server database. Thanks. ...

Run a Query using VBA without User Interface
Hello, I have a VBA Macro that Opens an Append Query (see below), which works great, except for the end user has to answer the following MsAccess prompts: 1) You are about to run an append query that will modify data in your table. (They have to click Yes) 2) You are about to append 1 row(s). (They have to click Yes) I'd rather them not have to answer either question. Instead I'd like the Append Query to run and do what it's asked without any human intervention. Can this be done? Please help! VBA Macro Code: DoCmd.OpenQuery "tblTask_List Query", acViewNorm...

Using "OR" in an IF statement
I am trying to use the command OR in an If statement and I am having no luck. In Lotus 123 I could string commands by using #OR# to produce a common result. For example: =IF(J3="INVEST" #OR# IF(K3 = "INVEST",1,"NO")) I can't seem to make this work in Excel. Can anyone provide me with a correction? Doug, Like this =IF(OR(J3="Invest",K3="Invest"),"The true condition","the false condition") If the true or false condition is numeric then drop the quotes -- Mike When competing hypotheses are other...

unable to scroll the page
on microsoft office frontpage 2003 - when i up loaded my web pages to my web site www.millertimeauction.com , there is no sroll bar for up & down of page - any help what browser? it scrolls for me in IE8 scroll bar will only appear if it needs to -- ~~~~~~~~~~~~~~~~~~ Rob Giordano Microsoft MVP Expression Web "FrontPage Error" <FrontPageError@discussions.microsoft.com> wrote in message news:EC19C7CE-1C5A-4872-A47B-2C04BD7E96A7@microsoft.com... > on microsoft office frontpage 2003 - when i up loaded my web pages to my > web > s...

Unable to start POP3, NNTP, IMAP4...
Dear all, I'm evaluating to install Exchange 2003. After the installation I find the said protocol haven't been started. I tried to start them in "Servers --> Server Name --> Protocols" but no help. Please comment.... Thanks!! Background: Windows 2003, Exchange 2003, Active Directory DC with all roles of FSMO as it's the first DC in the forest. Thank you very much!! -- Are you boring? Let's come to talk together... ^^ news://news.hk4u.com/hk4u.2hit6 Those services are disabled by default in Exchange 2003. Go to Administrative Tools, Services and enable...

how to use cursor to navigate active cells
With our Excel 2003, I could navigate to different cells by using the cursor keys. The cursor up key moved the active cell up. Left, right and down moved the active cell in the appropriate direction. I could select multiple cells by holding the shift key down and using the cursor keys to start selecting large groups of cells. Now, with Excel 2007, the cursor keys move the sheet around in the window, instead of moving the active cell in the indicated direction. I have found no way to select multiple cells. How can I get my Excel 2007 cursor keys to move the active cell, instead of moving t...

Running Total in report using net of two columns in third column
I have a client time/fees database of over 22k records. I have a report which provided a summary of all time booke and all fees charges to that client. What I require is two additional columns the first which provides a running total of time bookings and the second which provides a running total of the net of the time booked field less the fees charged field, i.e. the net of time bookings which have not been invoiced. I can do this in excel but in access I appear to be getting data from other clients which should not be included in the report. What type of field are you usin...

Unable to conect
Hi, I have set up my email account to work with aol using the guidlines for outlook 2002 but it is still unable to connect. Any suggestions? Thanks. John <John@discussions.microsoft.com> wrote: > I have set up my email account to work with aol using the guidlines > for outlook 2002 but it is still unable to connect. Any suggestions? Since you pay AOL for their service, my suggestion is to ask AOL. -- Brian Tillman ...

Unable to click on charts & unable to create any new charts Excel
Hi Just started using Microsoft Excel 2007 and I seem to have done something that means the chart option is unavailable. The chart section is now grey and all charts I have created are 'locked' I cannot click on them anywhere. I'm working on a project and need it finished by Monday. Do you mean that if you click on a chart it does not get a border to show it is activated and there are no range-finder borders around the data that makes the chart? This is a bit odd. Have you tried a new workbook to see if the problem is with just this one? My advice with all odd things is...

Using secondary email when distributing a Campaign Activity
Hello everyone, I'm looking for a way to use the marketing list's member primary AND secondary emails when send a email mass mailout from a campaign activity. I believe we could do it using the sdk, but am not sure how (plug-in, workflow?) Has anyone achieved this somehow? Thanks Hi Fred, Yes, our latest VEM (Vizola eMarketing Addin) module has this feature, please checkout http://www.vizola.com/vem - you can download and try the evaluation version - it also includes all the template usage + tracking and bounce features you need. On the COMPOSE EMAIL screen you are presented w...

Finesse in using Outlook Mail Features for Heavy Email Volume
Help- A long-time user of Outlook, I am now in a job that requires me to handle lots of volume into two different MS Exchange Accounts, and review two additional accounts. I was limping along using standard organizing techniques (i.e. personal folders and archiving), but am nearing a meltdown. I'm guessing that I have nearly 8,000 email scattered into different personal folders. I'm finding it cumbersome to deal with anymore. I am looking for some suggestions for efficiently organizing my messages, that will keep my system from crashing (which I feel is just around the corner), y...

allow conditional printing using label wizard
When creating labels for shelfs allow conditional printing of fields. for example if an item is on sale print the sale price instead of the regular price. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGroups/d...

using a command button in excel
Hi.. I am making a product price calculation sheet for my company & want to know how i can use a command button. with a command button can be name as ADD & once clicked should save all the details in the current sheet to a cumulative excel sheet. With this i can create a cumulative sheet where i can see all the data i have seleted. Please HELP... Thanks & regards The command button is a tool that creates an event which triggers an action That action is determined by a procedure (macro) which is either attached (button from Forms Toolbar) to the button...

I am unable to send e-mails -unable to download files from IMAP.
Please help. I am so frustrated with this In news:4564BC25-92D9-4094-A598-A23848856E5F@microsoft.com, ajmtextiles <ajmtextiles@discussions.microsoft.com> typed: > Please help. > > I am so frustrated with this I can understand why you might be frustrated, but you've provided no useful information for anyone to go on, so I doubt anyone can help you. When you post in here, always include your version, SP level, and mode (if applicable) of Outlook - you can find this information in Help | About. Also include the type of mail account(s) you use and any other pertinent de...