From: Larry on 13 Feb 2010 18:53 Hi, I am using the following code to create a List View Control: //////////////////////////////////////////// // Adding List-View Columns TCHAR szText[256] = {0}; TCHAR szString[5][20] = { TEXT("Column 1"),TEXT("Column 2"),TEXT("Column 3") }; HWND hlistview = CreateWindowEx(0, WC_LISTVIEW, 0, WS_VISIBLE | WS_CHILD | WS_BORDER | LVS_ALIGNLEFT | LVS_REPORT | LVS_EDITLABELS, 40,90,430,200, hwnd, (HMENU)IDC_LIST1, hInst, NULL); SetWindowFont(hlistview,hfont0,TRUE); LVCOLUMN lvc; ListView_DeleteAllItems(hlistview); lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; for (int k = 0; k < 3; k++) { lvc.iSubItem = k; lvc.cx = 100; lvc.pszText = szString[k]; lvc.fmt = LVCFMT_LEFT; ListView_InsertColumn(hlistview, k, &lvc); } // Adding List-View Items and Subitems struct petinfo { TCHAR szKind[10]; TCHAR szBreed[50]; TCHAR szPrice[20]; }; petinfo pi[] = { {TEXT("Dog"), TEXT("Poodle"), TEXT("$300.00")}, {TEXT("Cat"), TEXT("Siamese"), TEXT("$100.00")}, {TEXT("Fish"), TEXT("Angel Fish"), TEXT("$10.00")} }; LVITEM lvi; lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; lvi.state = 0; lvi.stateMask = 0; for (int k = 0; k < 3; k++) { lvi.iItem = k; lvi.iSubItem = 0; lvi.lParam = (LPARAM) &pi[k]; int res = ListView_InsertItem(hlistview, &lvi); } //////////////////////////////////////////////////// while I get the list view collumn correct I don't get any items...what am I doing wrong? thanks
From: Igor Tandetnik on 13 Feb 2010 19:04 Larry wrote: > LVITEM lvi; > lvi.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE; > lvi.state = 0; > lvi.stateMask = 0; > > for (int k = 0; k < 3; k++) > { > lvi.iItem = k; > lvi.iSubItem = 0; > lvi.lParam = (LPARAM) &pi[k]; > int res = ListView_InsertItem(hlistview, &lvi); > } > //////////////////////////////////////////////////// > > while I get the list view collumn correct I don't get any items...what am I > doing wrong? lvi.mask claims you are setting text, but you never assign lvi.pszText -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
From: Larry on 13 Feb 2010 19:22 "Igor Tandetnik" <itandetnik(a)mvps.org> ha scritto nel messaggio news:et$tMlQrKHA.3408(a)TK2MSFTNGP06.phx.gbl... > lvi.mask claims you are setting text, but you never assign lvi.pszText Well, I thought I was with this: lvi.lParam = (LPARAM) &pi[k]; Also, by passing this: lvi.pszText = pi[k]; I get this: error C2440: '=' : cannot convert from 'petinfo' to 'LPWSTR'
From: Igor Tandetnik on 13 Feb 2010 19:56 Larry wrote: > "Igor Tandetnik" <itandetnik(a)mvps.org> ha scritto nel messaggio > news:et$tMlQrKHA.3408(a)TK2MSFTNGP06.phx.gbl... > > >> lvi.mask claims you are setting text, but you never assign lvi.pszText > > Well, I thought I was with this: > > lvi.lParam = (LPARAM) &pi[k]; This assigns to lParam (which you promised with LVIF_PARAM), not to pszText (which you promised with LVIF_TEXT but are not doing). Perhaps you plan to use a callback for retrieving item text - in this case, set pszText to LPSTR_TEXTCALLBACK and handle LVN_GETDISPINFO notification. > Also, by passing this: > > lvi.pszText = pi[k]; > > I get this: > > error C2440: '=' : cannot convert from 'petinfo' to 'LPWSTR' pszText is supposed to point to a string of text, not to some arbitrary structure. -- With best wishes, Igor Tandetnik With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
|
Pages: 1 Prev: Using an OCX class from a non-MFC, non-GUI app? Next: open iexplorer with url |