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

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


LV_ITEM and how to retrieve lParam with GetItem or GetItemD

Carlos Morales Mengotti -- cmengot@arrakis.es
Monday, April 29, 1996

MFC 4.0/Win 95

Using a ClistCtrl report view,  I populated the list with a LV_ITEM with =
mask =3D=20
LVIF_TEXT | LVIF_PARAM; with the contents of a table from a database that=
 worked=20
very well and the .lParam stored his value that it's a key for another ta=
ble(I=20
put a TRACE on that to be sure).
Later in the flow of the program the user can select a item and the .lPar=
am it=B4s=20
needed to seek the other table.
For that I use the following code (Of course I'am building in debug setti=
ng)

-------------------------------------------------------------------------=
-----
void CAgregarCitas::OnItemchangedListUnirContactos(NMHDR* pNMHDR, LRESULT=
*=20
pResult)=20
{
	NM_LISTVIEW* pNMListView =3D (NM_LISTVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here


#ifdef _DEBUG
	LV_ITEM lvitem;
	lvitem.mask =3D  LVIF_PARAM | LVIF_STATE ;=09
	lvitem.iSubItem =3D 0;
	lvitem.iItem =3D pNMListView->iItem;=09
	lvitem.stateMask =3D LVIS_SELECTED;=20
	if (!m_ListaDeContactosNotas.GetItem(&lvitem) )
		TRACE("GetItem no me funciona!!\n");
	else
	{
		if (lvitem.state =3D=3D LVIS_SELECTED)
		{
			TRACE("LVIS_SELECTED me da positivo\n");
			TRACE("El Item es el: %d\n", lvitem.iItem);
			TRACE("La key es el n=FAmero %ld\n", lvitem.lParam);=09
		}

	}

#endif

=09
=09
=09
	*pResult =3D 0;
}
-------------------------------------------------------------------------=
--------
Well lvitem.lParam it's always 0, lvitem.iItem has the rigth value. if I =
change=20
the .mask to get the lvitem.pszText value, that worked also, but I'm unab=
le to=20
retrieve the .lParam.

If I use the CListCtrl::GetItemData the DWORD data it's also 0.
It's my first work with CListCtrl and I'm sure that I making something wr=
ong.

Thanks

--=20
----------------------------
Carlos Morales Mengotti
C++ & Electronic Publishing
cmengot@arraki.es
cmengot@ran.es
Apartado 23
28210 Valdemorillo (Spain)
34 - 1 - 897.78.68
34 - 1 - 316.11.13
----------------------------



Norman L Covington -- doubleM@cris.com
Monday, April 29, 1996

Carlos Morales Mengotti wrote:
>=20
> MFC 4.0/Win 95
>=20
> Using a ClistCtrl report view,  I populated the list with a LV_ITEM wit=
h mask =3D
> LVIF_TEXT | LVIF_PARAM; with the contents of a table from a database th=
at worked
> very well and the .lParam stored his value that it's a key for another =
table(I
> put a TRACE on that to be sure).
> Later in the flow of the program the user can select a item and the .lP=
aram it=B4s
> needed to seek the other table.
> For that I use the following code (Of course I'am building in debug set=
ting)
>=20
> -----------------------------------------------------------------
-------------
> void CAgregarCitas::OnItemchangedListUnirContactos(NMHDR* pNMHDR, LRESU=
LT*
> pResult)
> {
>         NM_LISTVIEW* pNMListView =3D (NM_LISTVIEW*)pNMHDR;
>         // TODO: Add your control notification handler code here
>=20
> #ifdef _DEBUG
>         LV_ITEM lvitem;
>         lvitem.mask =3D  LVIF_PARAM | LVIF_STATE ;
>         lvitem.iSubItem =3D 0;
>         lvitem.iItem =3D pNMListView->iItem;
>         lvitem.stateMask =3D LVIS_SELECTED;
>         if (!m_ListaDeContactosNotas.GetItem(&lvitem) )
>                 TRACE("GetItem no me funciona!!\n");
>         else
>         {
>                 if (lvitem.state =3D=3D LVIS_SELECTED)
>                 {
>                         TRACE("LVIS_SELECTED me da positivo\n");
>                         TRACE("El Item es el: %d\n", lvitem.iItem);
>                         TRACE("La key es el n=FAmero %ld\n", lvitem.lPa=
ram);
>                 }
>=20
>         }
>=20
> #endif
>=20
>=20
>=20
>=20
>         *pResult =3D 0;
> }
> -----------------------------------------------------------------
----------------
> Well lvitem.lParam it's always 0, lvitem.iItem has the rigth value. if =
I change
> the .mask to get the lvitem.pszText value, that worked also, but I'm un=
able to
> retrieve the .lParam.
>=20
> If I use the CListCtrl::GetItemData the DWORD data it's also 0.
> It's my first work with CListCtrl and I'm sure that I making something =
wrong.
>=20
> Thanks
>=20
> --
> ----------------------------
> Carlos Morales Mengotti
> C++ & Electronic Publishing
> cmengot@arraki.es
> cmengot@ran.es
> Apartado 23
> 28210 Valdemorillo (Spain)
> 34 - 1 - 897.78.68
> 34 - 1 - 316.11.13
> ----------------------------

Carlos:

Use:
  m_ListCtrl.SetDataItem(iItem, (DWORD)lID);

In my application I do this at the time I am transferring the=20
data from the table to the list control. I grab the primary key,=20
which is a long .

Then during, let's say a OnItemchanged() message, I grab the lID=20
from the data:

long lID =3D (long)m_ListCtrl.GetDataItem(iITem)

or just

(long)m_ListCtrl.GetDataItem(iItem) within the argument of the=20
function; however, I may use it more than once, so to save the=20
function call repeatedly, I bring it into a auto variable.

at this point you can pass the lID to another table to see if it=20
is at some particular state, or whatever. The iItem is found=20
within the structure passed to the message handler, although you=20
may have to cast depending on which message handler you are=20
using.

The best sample MSVC has on the ListCtrl interfacing with a=20
database is DAOVIEW, he uses a ListView there, but same=20
principles.

I hope this helps,

Norman L Covington
doubleM@concentric.com 




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