Sorting the list control from callback function

8/28/2006 2:44 AM
Hi,

I am using a callback function for sorting the list control in report
view.

When user clicks on the header column then I call this function

here is the code :

void snip_CListCtrl_SortItems()
{
// The pointer to my list view control.
extern CListCtrl* pmyListCtrl;

// Sort the list view items using my callback procedure.
pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
}


static int CALLBACK
MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
// lParamSort contains a pointer to the list view control.
CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
CString strItem2 = pListCtrl->GetItemText(lParam2, 0);

return strcmp(strItem2, strItem1);
}


but the problem I found that lParam1 and lParam2 have the same valueb
i.e. 0,0 for each call,

how can I set that values and also how can I sort the sub items values
if I click on that column.

thanks 
Anup

0
8/28/2006 9:57:55 AM
vc.mfc 33608 articles. 0 followers. Follow

3 Replies
676 Views

Similar Articles

[PageSpeed] 43

That's because lParam1 and lParam2 are the ItemData values associated with
the list item (SetItemData). So if you haven't set anything for the items
using SetItemData those values are 0 by default.

It's a really bad design from microsoft, but we have to live with it.

AliR.

<anup.kataria@gmail.com> wrote in message
news:1156759075.185214.152670@b28g2000cwb.googlegroups.com...
> 8/28/2006 2:44 AM
> Hi,
>
> I am using a callback function for sorting the list control in report
> view.
>
> When user clicks on the header column then I call this function
>
> here is the code :
>
> void snip_CListCtrl_SortItems()
> {
> // The pointer to my list view control.
> extern CListCtrl* pmyListCtrl;
>
> // Sort the list view items using my callback procedure.
> pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
> }
>
>
> static int CALLBACK
> MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
> {
> // lParamSort contains a pointer to the list view control.
> CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
> CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
> CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
>
> return strcmp(strItem2, strItem1);
> }
>
>
> but the problem I found that lParam1 and lParam2 have the same valueb
> i.e. 0,0 for each call,
>
> how can I set that values and also how can I sort the sub items values
> if I click on that column.
>
> thanks
> Anup
>


0
AliR3470 (3236)
8/28/2006 3:10:22 PM
Maybe this article will help you some:

http://www.codeproject.com/buglist/listcontrolsortitemsbug.asp

Tom

<anup.kataria@gmail.com> wrote in message 
news:1156759075.185214.152670@b28g2000cwb.googlegroups.com...
> 8/28/2006 2:44 AM
> Hi,
>
> I am using a callback function for sorting the list control in report
> view.
>
> When user clicks on the header column then I call this function
>
> here is the code :
>
> void snip_CListCtrl_SortItems()
> {
> // The pointer to my list view control.
> extern CListCtrl* pmyListCtrl;
>
> // Sort the list view items using my callback procedure.
> pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
> }
>
>
> static int CALLBACK
> MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
> {
> // lParamSort contains a pointer to the list view control.
> CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
> CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
> CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
>
> return strcmp(strItem2, strItem1);
> }
>
>
> but the problem I found that lParam1 and lParam2 have the same valueb
> i.e. 0,0 for each call,
>
> how can I set that values and also how can I sort the sub items values
> if I click on that column.
>
> thanks
> Anup
> 


0
tserface (3861)
8/28/2006 3:24:20 PM
Unfortunately, the lParam1 and lParam2 cannot be used as you used them here.  In fact, you
cannot MAKE them usable in this way.

While I agree that the whole sorting mechanism is more than a little weird, the wParam and
lParam must encode information about what the sort information is, and it cannot be an
index into the list control.  So the GetItemText here just plain won't work, and can't be
made to work.

You would have to set the LPARAM information of the list item to point to the string, or a
data structure containing the string, that represents the sort information.
					joe

On 28 Aug 2006 02:57:55 -0700, anup.kataria@gmail.com wrote:

>8/28/2006 2:44 AM
>Hi,
>
>I am using a callback function for sorting the list control in report
>view.
>
>When user clicks on the header column then I call this function
>
>here is the code :
>
>void snip_CListCtrl_SortItems()
>{
>// The pointer to my list view control.
>extern CListCtrl* pmyListCtrl;
>
>// Sort the list view items using my callback procedure.
>pmyListCtrl->SortItems(MyCompareProc, (LPARAM) pmyListCtrl);
>}
>
>
>static int CALLBACK
>MyCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
>{
>// lParamSort contains a pointer to the list view control.
>CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
>CString strItem1 = pListCtrl->GetItemText(lParam1, 0);
>CString strItem2 = pListCtrl->GetItemText(lParam2, 0);
>
>return strcmp(strItem2, strItem1);
>}
>
>
>but the problem I found that lParam1 and lParam2 have the same valueb
>i.e. 0,0 for each call,
>
>how can I set that values and also how can I sort the sub items values
>if I click on that column.
>
>thanks 
>Anup
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
8/29/2006 2:08:20 AM
Reply:

Similar Artilces:

Sorting a protected worksheet
Is it possible to Sort a protected worksheet that has protected formulas? I have a Workbook_Open sub that unprotects, then protects the active worksheet (see below). The worksheet still won't allow sorting, even though I have the AllowSorting:=True. Also, is it possible to have the code clear itself or disable the Workbook_Open sub after it runs? The original is an Macro Enabled Workbook. On open, it's refreshed, then saved on our network as Workbook.xls format. It's annoying to end user to have the code run every time they open the workbook. Sub Workbook_O...

why won't word 2007 release control of a .rtf file after exiting w
I AM HAVING TROUBLE WITH ACCESS TO RICH TEXT FILES BY PROGRAMS OTHER THAN WORD------ AFTER THE FILE OPEN IN WORD IS CLOSED AND EVEN AFTER WORD HAS BEEN SHUT DOWN (EXITED) ---------- I GET THE ERROR MESSAGE THAT THE FILE IS "IN USE" BY WORD WHEN (FOR EXAMPLE) AN ATTEMPT IS MADE TO DELETE IT ---- SOMETIMES WHEN RE-OPENING THE FILE AFTER RE-STARTING WORD THE FILE CANNOT BE SAVED BECAUSE IT IS IN "READ ONLY" MODE ------- AFTER MUCH FIDDLING AROUND I FINALLY MANAGED TO DELETE THE PROBLEM FILE ONLY TO HAVE THE SAME PROBLEM RETURN WITH A DIFFERNT FILE ----- WORD 200...

no internet connection
this is a very frustration situation. last week, i got a rid of several trojans and malware using malwarebytes. it did an excellent job, however it seemed to leave me with 2 problems - no internet connectivity and no sound on my media player. so i tried a number of things and eventually arrived at the following computer configuration, but first, heres my system info: i run xp sp2 on a msi rs480m2 series amd athlon 64 (socket 939) ms-7093 motherboard with a ati radeon express 200 series display. i ran belarc and under communications, it tells me that i have a realtek rtl 8139 fa...

How to show a tool tip on an activex control embedded in a Cdialog
Hi, I have an activex control(IWebBrowser2) control embedded in a CDialog. I need to show a tool tip on the control depending on some conditions. I have tried the following approaches- 1)Tried using CTooltipCtrl object in the CDialog derived class in which the control is embedded. The whole show - override PreTranslateMessage() { m_tooltip.relayEvent(pMsg); } This does not work. 2) Used the above approach in the class implementing the IWebBrowser2 contol - which is a CWnd derived class. This also does not work. 3)I created my own CWnd derived tooltip class and show it when some conditio...

Dependant parts list -lookup
Hello trying to find a way to have a row of dependant columns ,where the first row has a drop down menu with a list of parts like a lamp body, then the next cell over shows a list which would change depending on the first selection. until a whole part # is created from all the indiviual pieces. That then would return in a different cell a quantity of available for sale and a price specific to that unique part #. I already have a sheet that has the quantities and pricing. Having one Data Validation cell display a list that is dependent on the selection made in another Data Validation ce...

Exch2003: find unused distribution lists
Hi What's the best way to find which of our distribution lists have not had mail sent to them recently, say the last month? We have 3 Exch 2003 Std servers, single AD domain, 3 AD sites. Thanks, Graeme. On 20 Mar 2007 01:03:00 -0700, graeme.donaldson@gmail.com wrote: >Hi > >What's the best way to find which of our distribution lists have not >had mail sent to them recently, say the last month? We have 3 Exch >2003 Std servers, single AD domain, 3 AD sites. > >Thanks, >Graeme. Haven't got a way of telling you from Active Directory this information. I re...

sort certain datas in a wide range of datas
Say I have 3 columns with lots of datas: Column A: Order # Column B: Part# Column C: Catergory # A2: Order# 021006 B2: 111 C2: Wire A3: Order# 021006 B3: 222 C3: Machine A4: Order# 021006 B4: 333 C4: Tool A5: Order# 021006 B5: 444 C5: Tape A6: Order# 021007 B6: 222 C6: Machine A7: Order# 021007 B7: 333 C7: Tool A8: Order# 021007 B8: 444 C8: Tape A9: Order# 021008 B9: 111 C9: Wire A10: Order# 021008 B10:222 C10: Machine A11: Order# 021008 B11:555 C11: Bearing What I n...

Delete "Suggest Names" list
Under Advanced Email Options there is a option to "Suggest names while completing TO, CC and BC fields" How can the contents of this list be cleared? This may help: Deleting Unused Addresses from AutoSuggest As you probably have noticed, when you begin to type a name or email address in the To, CC or Bcc field of an email, Outlook displays a list of suggested email addresses. If there is an address in that list that you would rather not have suggested, just scroll to it using the arrow keys, then press the Delete key to delete it. The "deleted" address remains in ...

Sort Order Doesn't Seem Correct
Hello: I have a program that sorts a text column and then does a sequence check to make sure it is in ascending order so I can use a Vlookup using the option where data must be in a sorted order. Here is a snippet of the data where it doesn't sort correctly. The field is defined as text. If you copy and paste this into a column you should have the same strange results in that it doesn't sort it in ASCII order. The dash character (Hex 2D) sorts AFTER the letter "K", which has a Hex code of "4B". So it is not sorting correctly and my VLookup fails...

Sorting on dates
In 2007, is there a way to sort newest to oldest but put the empty fields on top instead of at the bottom? Thanks, Tom How about changing (edit|replace) the blanks to a date way out in the future, then do the sort and another edit|replace to change it back to empty cells. tshad wrote: > > In 2007, is there a way to sort newest to oldest but put the empty fields on > top instead of at the bottom? > > Thanks, > > Tom -- Dave Peterson "Dave Peterson" <petersod@verizonXSPAM.net> wrote in message news:4A6E2E0A.23C9D11E@verizonXSPAM.net... > H...

Calendar Control (ActiveX) Access 2003
I want to use the Calendar Control to display a baseball game schedule. Example: Show a calendar with all the games being played that month. Each date would be colored as white for home and grey for away. Each date would also contain the team being played's logo, and the time the game starts (local). I want the control to read the schedule file and display the data for each team. I'm not sure how to go about it. Any help will be greatly appreciated A Flex Grid Control will probably do what you want. Have a look at - http://www.rogersaccesslibrary.com/Otherdownload.asp?SampleN...

Check List Report
I want to create a report containing a check list with a check box on the right side of the check list item so I can check items off from the printed report. I've created a table with the item and a yes/no field but the check box for the yes/no is awfully small. What is the best way to generate a box next to the item? Was wondering if anyone had any ideas for me on how to accomplish this. Thanks, James James In your report definition (design view), change the font size of the checkbox. Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author m...

If Function Limitation
How can one have more than 7 If Functions nested, I have the need to create more than 7 If Functions, how can I go around this problem, I consulted the Help Section and it states: "Up to seven IF functions can be nested as value_if_true and value_if_false arguments" Your help is most appreciated! In practically every instance I run across where you need more than 7 IF statements, the problem can be solved by constructing a Lookup table of values to be matched and their corresponding return value. Example: Col_A Col_B Apple 1 Berry 100 Cat 11 Date 21 Eel 35 Fruit 106 Grate ...

Set a control value On Opening the Form
I have a continuous form based on an outer join. The pertinent fields in the query are SELECT tblDealer.ShopID, tblDealer.ShopName, IIf(IsNull(tblContract2008Temp.ShopName),tblDealer.ShopName,tblContract2008Temp.ShopName) AS FindShopName, FROM tblDealer LEFT JOIN tblContract2008Temp ON tblDealer.ShopID = tblContract2008Temp.ShopID ORDER BY tblDealer.ShopName; I have a hidden control set to the FindShopName value. When the form opens, if any txtShopName value is null, I want it set to the FindShopName value. What happens is the form opens with the control still blank, but it fills...

Adding valitation list
Is it possible to add valitaion list that contains same addres in every different worksheet in my workbook and uptates it automatically when i add new worksheet. ...

Controlling Access to Contact's History
Is there a way to set a security role up so a user can't delete items from a Contact's History? The user would still need rights to read/ write to the contact record. Go to Settings-->business unit settings-->security roles Choose a role to edit (other than system administrator, you can't change that one). Select the Core Records tab. History, in terms of tasks and appointments, is controlled by the Activity row. History, in terms of notes, is controlled by the Note row. You can set the read and write "pies" seperately from the Delete "pie". Clear th...

Offline address lists Problem
Hi, I´ve a exchange 2000 clustered enviroment in the company, but outlook users didn´t syncronize offline address list, they receive a error. Everything it´s ok in the environment, I configured a server to host the offline address list and the DC´s are OK. What can be the problem? Thanks! -- Gustavo Z. Velozo ...

How to add function to ie to parse html of current web page??
He there, i am looking for a way to add a function to ie7 or ie8 which parses the html code of the current web page and then copies parts of it to the clipboard so the data can be used via copy & paste. Any hints on how to add this kind of functionality would be highly appreciated. thx. Leon wrote: > He there, > > i am looking for a way to add a function to ie7 or ie8 which parses the > html code of the current web page and then copies parts of it to the > clipboard so the data can be used via copy & paste. > > Any hints on how to add ...

smart list go tos
I am trying to change the documents: portion with a go to on the window "Purchase Order Processing Document Inquiry" Take a look at my response to this post. However, this was not entirely tested. http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?&query=mariano+gomez+SLB&lang=en&cr=US&guid=&sloc=en-us&dg=microsoft.public.greatplains&p=1&tid=37216782-e2be-45a4-8d28-6e3f73f11ca5&mid=37216782-e2be-45a4-8d28-6e3f73f11ca5 Best regards, -- MG.- Mariano Gomez, MIS, MCP, PMP Maximum Global Business, LLC http://www.maximumglobalbusines...

adds staff to access list to ALL PROJECTS if same as their departm
A procedure was written to update all projects, adds staff to access list to ALL PROJECTS if they are the same as their home department. It would be useful to know if there were a feature to define default projects by a given criteria - i.e. By department. [d]elete accesslest insert accesslest (PACONTNUMBER, PAPROJNUMBER, EMPLOYID, ContractEntry, ContractInquire, ContractReport, ContractReview, ProjectEntry, ProjectInquire, ProjectReport, ProjectReview, ALEntry, ALInquire, ALReport, ALReview, EEEntry, EEInquire, EEReport, EEReview, ELEntry, ELInquire, ELReport, ELReview, FFEnt...

Autofilter's drop down list goes missing
I am using autofilter on a two excel work sheets. Randomly the drop down arrows locks up and will not display the drop down lists. If I uncheck autofilter and reselect the data then reselect autofilter it enables the drop down arrows again, although this does not always work, some times I have to close excel and open it again. The document was originally created in excel 2000 but the problem is occurring in excel 2003. I have been able recreate the problem on separate machines different hardware (Compaq and Dell), so I know the hardware is not the issue. Again the method of reproducing the err...

How do I edit the Current Multilevel List in Word 2007??
I'm so frustrated. I just want to change my numbering setup for the list style. I want to edit the Multilevel list under "Current List" which is the list numbering that I have assigned to my styles in my document. The document is a very large document originally created in Word 2003. I'm a new Word 2007 user. Please tell me how to edi t the numbering setup. YoOu know, like you can do in Word 2003 when you "Modify" your "Heading n" style, choose "Numbering" and then clicking "Customize" under the mutlilevel numbering box. ...

forward or reply of messages containing "numbered lists"
I posted the following yesterday as a reply to an old posting (Nov). Since then I have confirmed that this problem (like similar ones) is associated with using WORD as my email editor. Deselecting WORD solves the problem. If anyone has an alternate solution, please post. Thanks. ~bit ================================================= I recently discovered similar (but not identical) behavior with my Outlook 2002 on XP SP2: 1) I send an HTML email (Word is the editor) with a numbered list of items (just like I'm using here) 2) The recipient responds with comments inserted after e...

Attaching a tab control to another tab control
I have a large tab control and I added a smaller one to it. I only want the smaller tab control to be displayed when I am on the first tab of the larger one. How do I attach it to the larger tab control's first tab? Thanks twen wrote: >I have a large tab control and I added a smaller one to it. I only want the >smaller tab control to be displayed when I am on the first tab of the larger >one. How do I attach it to the larger tab control's first tab? A tab control can not contain another tab control. You could try placing a subform with a tab control in the main tab co...

Search function
What would be the typical approach to building a search function? I would assume that, unless there's a built-in facility that I've not had an occasion to encounter, that one would step through a RecordsetClone of a form's RecordSource using strIn on the field of interest inclusive of logic that keeps track of the last record where a match was found and use of a function key to look for the next match? (I thought I'd seen somewhere in the past where VBA had access to the VBA editor's Find function, but so far I've not found any such reference.) Thanks, Bill The m...