From: Larry on
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: Random on
On Feb 13, 3:53 pm, "Larry" <dontmewit...(a)got.it> wrote:
>  for (int k = 0; k < 3; k++)
>  {
>   lvi.iItem    = k;
>   lvi.iSubItem = 0;
>   lvi.lParam   = (LPARAM) &pi[k];

You're not setting the text of each item:

lvi.pszText = pi[k].szKind;

>   int res = ListView_InsertItem(hlistview, &lvi);

And I'm guessing you'll want to set the text for the subitems too:

ListView_SetItemText(hlistview, k, 1, pi[k].szBreed);
ListView_SetItemText(hlistview, k, 2, pi[k].szPrice);

From: Larry on

"Random" <random.coder(a)gmail.com> ha scritto nel messaggio
news:3afab119-cbb8-4b1f-a9d7-858fc42392c1(a)b1g2000prc.googlegroups.com...

> You're not setting the text of each item:

Ok, thanks! So, do you think I could just get rid of the "lvi.lParam" as
well as just using "LVIF_TEXT | LVIF_STATE" in lvi.mask?

By the way, do you think there is any way to put some lines in between
rows??

From: Random on
On Feb 13, 5:15 pm, "Larry" <dontmewit...(a)got.it> wrote:
> "Random" <random.co...(a)gmail.com> ha scritto nel messaggionews:3afab119-cbb8-4b1f-a9d7-858fc42392c1(a)b1g2000prc.googlegroups.com...
>
> > You're not setting the text of each item:
>
> Ok, thanks! So, do you think I could just get rid of the "lvi.lParam" as
> well as just using "LVIF_TEXT | LVIF_STATE" in lvi.mask?

Sure, if you have no intention of using lParam, then there's no need
to set it. The ListView certainly doesn't care what you do with it.

> By the way, do you think there is any way to put some lines in between
> rows??

Call ListView_SetExtendedListViewstyleEx with LVS_EX_GRIDLINES.
From: Larry on

"Random" <random.coder(a)gmail.com> ha scritto nel messaggio
news:688ffd38-6975-4cb9-980f-7beee10350df(a)z10g2000prh.googlegroups.com...

> Call ListView_SetExtendedListViewstyleEx with LVS_EX_GRIDLINES.

Ok. is there any differences between:

ListView_SetExtendedListViewStyleEx(hlistview, 0, LVS_EX_GRIDLINES);

and

ListView_SetExtendedListViewStyleEx(hlistview, LVS_EX_GRIDLINES,
LVS_EX_GRIDLINES);