15 мая 2023 года "Исходники.РУ" отмечают своё 23-летие!
Поздравляем всех причастных и неравнодушных с этим событием!
И огромное спасибо всем, кто был и остаётся с нами все эти годы!

Главная Форум Журнал Wiki DRKB Discuz!ML Помощь проекту


Problem with LVIF_PARAM....

Fabio Ferracchiati -- fabio@infobyte.it
Tuesday, September 10, 1996

Environment: Visual C++ 4.1, Windows 95

Hello,
I have a problem. I should use a list view like a listbox for the SetItemData 
method.
In another words, I should store a string for every row of list view, and this
string should be invisible.
For a ListBox is simple...
CMyListBox.SetItemData(Index, pszString)

But for a LisyView?
Is there anyboby help me?

Thank you in advance.




Jeff -- JEFFF@twgi.com
Tuesday, September 10, 1996

[Mini-digest: 2 responses]


Hello,

You can call CListView's GetListCtrl() member function to get a pointer   
to the view's underlying list control. The CListCtrl class supports a   
SetItemData() member function. You should be able to write

CListView * pView;
CListCtrl * pCtrl;

// pView is set to the CListView before this code is executed

pCtrl = pView->GetListCtrl();
pCtrl->SetItemData(...);

 ----------
From:  mfc-l
Sent:  Tuesday, September 10, 1996 3:38 PM
To:  'MFC Mailing List'
Subject:  Problem with LVIF_PARAM....

Environment: Visual C++ 4.1, Windows 95

Hello,
I have a problem. I should use a list view like a listbox for the   
SetItemData
method.
In another words, I should store a string for every row of list view, and   
this
string should be invisible.
For a ListBox is simple...
CMyListBox.SetItemData(Index, pszString)

But for a LisyView?
Is there anyboby help me?

Thank you in advance.


-----From: Jeff Wishnie 

int index;
LONG lParam;

It's exactly the same. Use CListCtrl::SetItemData(index, lParam)

- Jeff



Roger Onslow/Newcastle/Computer Systems Australia/
Wednesday, September 11, 1996

[Mini-digest: 5 responses]

>In another words, I should store a string for every
>row of list view, and this string should be invisible.

Every row in a list view has an LPARAM value associated with it.
You can specify this when you create the list view
Or you can modify an existing row and change its LPARAM.
You can also easily extract the LPARAM value.
Just like with a list box the LPARAM can contain a
string pointer etc (just cast to LPARAM before storing)

NOTE: preferred way to cast between a char* and an LPARAM
in C++ is like this:
 LPARAM lParam = reinterpret_cast(lpString);

eg. here is how I append a row to a list control
 // Call this to append a row to the list control
 ASSERT_VALID(this);
 LV_ITEM lvI;
 lvI.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE;
 lvI.iItem = GetItemCount();
 lvI.iSubItem = 0;
 lvI.state = 0;      
 lvI.stateMask = 0;  
 lvI.pszText = lpLabel;
 lvI.cchTextMax = MAX_ITEMLEN;
 lvI.iImage = 0;
>>>>> lvI.lParam = lParam; // the data value associated with the row
 m_MyListCtrl.InsertItem(&lvI);

Hope this helps you
Roger Onslow
-----From: antony@cauchy.miel.mot.com (ANTONISAMY A[MIEL])

Hi Fabio Ferracchiati,
	Use the CListCtrl::SetItemData(int nItem, DWORD dwData) to store hidden
	values in the CListCtrl of the CListView. dwData can be a pointer to
	a string in your case.

Antony
-----From: Mario Contestabile

LV_ITEM itemAdder;
memset(&itemAdder,0,sizeof(LV_ITEM));
itemAdder.mask = LVIFxxx;
itemAdder.mask |= LVIF_PARAM;
...
itemAdder.lParam = (LPARAM)pszString;

If your list view allows sorting, you'll want to make sure the data is still 
valid.
Chow fabio
mcontest@universal.com

-----From: jabaudoin@halnet.com (Jody Baudoin)

Concerning the suggestion of using SetItemData,
as mentioned in the Mini-digest.

BEWARE:  use of SetItemData and SetItemDataPtr may not be compatible

Once upon a time, several versions of MFC ago, I tried to
use SetItemData and SetItemDataPtr on the same list elements
of a list box.  This was a no-no because the two functions
used the same class variable.  The second call over-wrote the
first calls work.  The DOCS have no warnings about this, so
beware.

jabaudoin@halnet.com


-----From: Jim Leavitt 

Fabio:
CListCtrl has the SetItemData method:
CListCtrl::SetItemData( int nItem, DWORD dwData )

Notice that you're only able to set the DWORD dwData as your data. The =
way I've done this in the past is to create an array or collection of =
the data items (in your case, strings) and call SetItemData passing in =
the index of the data item from the array that I was interested in. This =
may not be the best way but it's very straight forward and simple.=20

Jim Leavitt




| Вернуться в корень Архива |