Yet another CListCtrl() question from a newbie (sort question) on Dialog based project 
Author Message
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project

Ok...  I think I'm close on this :)  I get the AfxMessageBox() whenever I
click on a column heading, my question is w/ LPARAM.
My list is all CStrings loaded like this:

CString iNum, iPrice, iDealerDisc, iCost, iDa{*filter*}tered, iDateSold, iDesc,
iLocation;

 // some assignment stuff

// add to list
m_List.InsertItem(index, iNum, image)
m_List.SetItemText(index, 1, iPrice);
m_List.SetItemText(index, 2, iDealerDisc);
m_List.SetItemText(index, 3, iCost);
m_List.SetItemText(index, 4, iDa{*filter*}tered);
m_List.SetItemText(index, 5, iDateSold);
m_List.SetItemText(index, 6, iDesc);
m_List.SetItemText(index, 7, iLocation);

Here is the sort stuff...

void CAntiqueRebornDlg::OnColumnclickList(NMHDR* pNMHDR, LRESULT* pResult)
{
    NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
    m_List.SortItems(SortAvailList, pNMListView->iSubItem);

    *pResult = 0;

Quote:
}

int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
lParam2, LPARAM lParamSort)
{
     int result = 0;
    AfxMessageBox("I'm here");
    return result;

Quote:
}

I don't seem to be able to convert lParam1 back to CString so I can do a
compare against lParam1/2)?
I gave up trying to get that LV_ITEM way of adding items working (made a
struct called pItem w/ 7 CString's and tried inserting it with LV_ITEM lvi
but I just get blanks so I would like to get it working this way for now))

Thanks!
K



Sat, 19 Jun 2004 22:53:19 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project

Quote:
>int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
>lParam2, LPARAM lParamSort)
>{
>     int result = 0;
>    AfxMessageBox("I'm here");
>    return result;
>}

>I don't seem to be able to convert lParam1 back to CString so I can do a
>compare against lParam1/2)?

The MFC documentation of sorting a list control is quite misleading.
The lParam's you get in the sort function are values that you set
per-item using SetItemData.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sun, 20 Jun 2004 00:56:28 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project
--
-------------------------------------------------------------------------
Free software  - Baxter Codeworks  www.baxcode.com
-------------------------------------------------------------------------


Quote:

> void CAntiqueRebornDlg::OnColumnclickList(NMHDR* pNMHDR, LRESULT* pResult)
> {
>     NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
>     m_List.SortItems(SortAvailList, pNMListView->iSubItem);

>     *pResult = 0;
> }

> int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
> lParam2, LPARAM lParamSort)
> {
>      int result = 0;
>     AfxMessageBox("I'm here");
>     return result;
> }

> I don't seem to be able to convert lParam1 back to CString so I can do a
> compare against lParam1/2)?
> I gave up trying to get that LV_ITEM way of adding items working (made a
> struct called pItem w/ 7 CString's and tried inserting it with LV_ITEM lvi
> but I just get blanks so I would like to get it working this way for now))

In my code, I have something like this:
----------------

int CALLBACK CSelListCtrl::CompareFunction(LPARAM lParam1, LPARAM lParam2,
LPARAM lParamData)
{
   CMyListCtrl* pListCtrl = reinterpret_cast<CMyListCtrl*>(lParamData);
   ASSERT(pListCtrl->IsKindOf(RUNTIME_CLASS(CListCtrl)));
...
     int nSortCol = pListCtrl->m_ctrlHeader.GetSortCol();
    CString sText1 = pListCtrl->GetItemText((int)lParam1, nSortCol);
     CString sText2 = pListCtrl->GetItemText((int)lParam2, nSortCol);

    res =  sText1.CompareNoCase(LPCSTR(sText2));



Sun, 20 Jun 2004 01:24:09 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project
Ok..  so when I'm loading an item into the list I should toss in a
m_List.SetItemData(index, ??)?  and that method wants a 32 bit value
specific to the item.  So what would the 32bit value of the CString?  I'm
lost ;)

Thanks!
K


Quote:
> >int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
> >lParam2, LPARAM lParamSort)
> >{
> >     int result = 0;
> >    AfxMessageBox("I'm here");
> >    return result;
> >}

> >I don't seem to be able to convert lParam1 back to CString so I can do a
> >compare against lParam1/2)?

> The MFC documentation of sorting a list control is quite misleading.
> The lParam's you get in the sort function are values that you set
> per-item using SetItemData.

> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> My address is altered to discourage junk mail.
> Please post responses to the newsgroup thread,
> there's no need for follow-up email copies.



Sun, 20 Jun 2004 01:28:09 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project
int CALLBACK CAntiqueRebornDlg::SortAvailList(LPARAM lParam1, LPARAM
lParam2, LPARAM lParamSort)

{

    int rValue = 0;

    CString sText = m_List.GetItemText((int)lParam1, 0);

    return rValue;

Quote:
}

gives me
AntiqueRebornDlg.cpp(1528) : error C2228: left of '.GetItemText' must have
class/struct/union type

I have to be missing something :)  I'm close :)


Quote:
> --
> -------------------------------------------------------------------------
> Free software  - Baxter Codeworks  www.baxcode.com
> -------------------------------------------------------------------------



> > void CAntiqueRebornDlg::OnColumnclickList(NMHDR* pNMHDR, LRESULT*
pResult)
> > {
> >     NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
> >     m_List.SortItems(SortAvailList, pNMListView->iSubItem);

> >     *pResult = 0;
> > }

> > int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
> > lParam2, LPARAM lParamSort)
> > {
> >      int result = 0;
> >     AfxMessageBox("I'm here");
> >     return result;
> > }

> > I don't seem to be able to convert lParam1 back to CString so I can do a
> > compare against lParam1/2)?
> > I gave up trying to get that LV_ITEM way of adding items working (made a
> > struct called pItem w/ 7 CString's and tried inserting it with LV_ITEM
lvi
> > but I just get blanks so I would like to get it working this way for
now))

> In my code, I have something like this:
> ----------------

> int CALLBACK CSelListCtrl::CompareFunction(LPARAM lParam1, LPARAM lParam2,
> LPARAM lParamData)
> {
>    CMyListCtrl* pListCtrl = reinterpret_cast<CMyListCtrl*>(lParamData);
>    ASSERT(pListCtrl->IsKindOf(RUNTIME_CLASS(CListCtrl)));
> ...
>      int nSortCol = pListCtrl->m_ctrlHeader.GetSortCol();
>     CString sText1 = pListCtrl->GetItemText((int)lParam1, nSortCol);
>      CString sText2 = pListCtrl->GetItemText((int)lParam2, nSortCol);

>     res =  sText1.CompareNoCase(LPCSTR(sText2));



Sun, 20 Jun 2004 02:17:32 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project
You don't use a CString; you use a CString *. THe 32-bit value is the pointer to the
CString.
        CString * s = new CString(_T("Heading"));
        c_ListCtrl.SetItemData(index, (LPARAM)s);
You need a handler to handle deletions that will free the string. However, if the strings
are from a fixed vocabulary, you can simply pass in the address of the CString in a fixed
table of CStrings and no deletion would be required.
                                joe

Quote:

>Ok..  so when I'm loading an item into the list I should toss in a
>m_List.SetItemData(index, ??)?  and that method wants a 32 bit value
>specific to the item.  So what would the 32bit value of the CString?  I'm
>lost ;)

>Thanks!
>K



>> >int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
>> >lParam2, LPARAM lParamSort)
>> >{
>> >     int result = 0;
>> >    AfxMessageBox("I'm here");
>> >    return result;
>> >}

>> >I don't seem to be able to convert lParam1 back to CString so I can do a
>> >compare against lParam1/2)?

>> The MFC documentation of sorting a list control is quite misleading.
>> The lParam's you get in the sort function are values that you set
>> per-item using SetItemData.

>> Dave
>> --
>> MVP VC++ FAQ: http://www.mvps.org/vcfaq
>> My address is altered to discourage junk mail.
>> Please post responses to the newsgroup thread,
>> there's no need for follow-up email copies.

Joseph M. Newcomer [MVP]

Web: http://www3.pgh.net/~newcomer
MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm


Sun, 20 Jun 2004 05:30:18 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project

Quote:
>Ok..  so when I'm loading an item into the list I should toss in a
>m_List.SetItemData(index, ??)?  and that method wants a 32 bit value
>specific to the item.

Yes, that's right.

Quote:
>  So what would the 32bit value of the CString?

You store something that you can use to determine the sort order - you
could store the item index, or a pointer to the CString (use
SetItemDataPtr is cleaner for that). If you store a pointer to a
CString (or any other allocated data), then that data has to live for
the life of the control.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sun, 20 Jun 2004 06:03:26 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project

Quote:
>You store something that you can use to determine the sort order - you
>could store the item index, or a pointer to the CString (use
>SetItemDataPtr is cleaner for that). If you store a pointer to a
>CString (or any other allocated data), then that data has to live for
>the life of the control.

Ah, I see Joe's reply has spelt this out.

Dave
--
MVP VC++ FAQ: http://www.mvps.org/vcfaq
My address is altered to discourage junk mail.
Please post responses to the newsgroup thread,
there's no need for follow-up email copies.



Sun, 20 Jun 2004 06:18:22 GMT  
 Yet another CListCtrl() question from a newbie (sort question) on Dialog based project
working great, thanks!



Quote:
> You don't use a CString; you use a CString *. THe 32-bit value is the
pointer to the
> CString.
> CString * s = new CString(_T("Heading"));
> c_ListCtrl.SetItemData(index, (LPARAM)s);
> You need a handler to handle deletions that will free the string. However,
if the strings
> are from a fixed vocabulary, you can simply pass in the address of the
CString in a fixed
> table of CStrings and no deletion would be required.
> joe


> >Ok..  so when I'm loading an item into the list I should toss in a
> >m_List.SetItemData(index, ??)?  and that method wants a 32 bit value
> >specific to the item.  So what would the 32bit value of the CString?  I'm
> >lost ;)

> >Thanks!
> >K



> >> >int CALLBACK CAntiqueRebordDlg::SortAvailList(LPARAM lParam1, LPARAM
> >> >lParam2, LPARAM lParamSort)
> >> >{
> >> >     int result = 0;
> >> >    AfxMessageBox("I'm here");
> >> >    return result;
> >> >}

> >> >I don't seem to be able to convert lParam1 back to CString so I can do
a
> >> >compare against lParam1/2)?

> >> The MFC documentation of sorting a list control is quite misleading.
> >> The lParam's you get in the sort function are values that you set
> >> per-item using SetItemData.

> >> Dave
> >> --
> >> MVP VC++ FAQ: http://www.mvps.org/vcfaq
> >> My address is altered to discourage junk mail.
> >> Please post responses to the newsgroup thread,
> >> there's no need for follow-up email copies.

> Joseph M. Newcomer [MVP]

> Web: http://www3.pgh.net/~newcomer
> MVP Tips: http://www3.pgh.net/~newcomer/mvp_tips.htm



Sun, 20 Jun 2004 22:50:17 GMT  
 
 [ 9 post ] 

 Relevant Pages 

1. Newbie question on Dialog based application

2. Newbie question: Getting a key pressed in a dialog-based application

3. Newbie question: Getting a key pressed in a dialog-based application

4. Yet Another Newbie Question/Keeping main() neat and tidy

5. Yet another newbie question

6. Yet another .net newbie question

7. ^yet^ another newbie question

8. Newbie: Yet another Datagrid / ADO question

9. yet another newbie question..

10. CFile/CCommon dialog question and DAO open question (yes, I'm a newbie)

11. sorted CListCtrl question

12. CListCtrl question (sorting)

 

 
Powered by phpBB® Forum Software