I have this code:


<code>
HWND hList = GetDlgItem(hDlg, IDC_LIST_CHARACTERS);

LVCOLUMN column;

// character
column.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;
column.pszText = "Character name";
column.cx = 200;
column.iSubItem = 1;
SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&column);

// number of bones
column.mask = LVCF_TEXT|LVCF_WIDTH|LVCF_SUBITEM;
column.pszText = "Number of Bones";
column.cx = 90;
column.iSubItem = 2;
SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&column);


LVITEM item;

item.mask = LVIF_TEXT|LVIF_;
item.pszText = "This is a test";
item.iItem = 0;
item.iSubItem = 1;
SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);


item.mask = LVIF_TEXT;
item.pszText = "asdasdasdasd";
item.iItem = 1;
item.iSubItem = 2;
SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);
</code>


When this finishes, there are no items listed in my list control. I have
stepped through the code and everything looks fine except that the result
from LVM_INSERTITEM is -1;
This is weird, I can insert the columns, what would be wrong with the item?

Anyone see a problem with this?

Thanks for reading,
Steve

Re: inserting item into list view by David

David
Tue Nov 22 16:41:42 CST 2005

>item.mask = LVIF_TEXT|LVIF_;
>item.pszText = "This is a test";
>item.iItem = 0;
>item.iSubItem = 1;
>SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);

Steve,

User LVM_INSERTITEM to inset the basic item, use LVM_SETITEMTEXT to
set any sub-item text. Set iSubItem to 0 for LVM_INSERTITEM.

Dave

Re: inserting item into list view by Igor

Igor
Tue Nov 22 16:46:01 CST 2005

Steve <sss@sss.com> wrote:
> I have this code:
>
> LVITEM item;
>
> item.mask = LVIF_TEXT|LVIF_;
> item.pszText = "This is a test";
> item.iItem = 0;
> item.iSubItem = 1;
> SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);
>
>
> item.mask = LVIF_TEXT;
> item.pszText = "asdasdasdasd";
> item.iItem = 1;
> item.iSubItem = 2;
> SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);
> </code>

You misunderstand how listview works. The text in the first (leftmost)
column is considered an item. Text in other columns belongs to subitems
of this item.

First, you must insert an item with LVM_INSERTITEM. It should have
iSubItem set to 0. The message returns an index of freshly inserted
item.

Then, you set subitems with LVM_SETITEM. Here, iItem should use the
index returned by LVM_INSERTITEM, and iSubItem should identify the
desired subitem (0 for the item itself).
--
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



Re: inserting item into list view by Steve

Steve
Tue Nov 22 17:03:03 CST 2005


> You misunderstand how listview works. The text in the first (leftmost)
> column is considered an item. Text in other columns belongs to subitems
> of this item.
>
> First, you must insert an item with LVM_INSERTITEM. It should have
> iSubItem set to 0. The message returns an index of freshly inserted
> item.
>
> Then, you set subitems with LVM_SETITEM. Here, iItem should use the
> index returned by LVM_INSERTITEM, and iSubItem should identify the
> desired subitem (0 for the item itself).
> --
> With best wishes,
> Igor Tandetnik

Thanks Igor!

I am much closer now ;)
But I still have a weird issue.
Here is the code that I am now using
<code>
item.mask = LVIF_TEXT;
item.pszText = "first item";
// item.iItem = 0;
item.iSubItem = 0;
LRESULT index = SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);


item.mask = LVIF_TEXT;
item.pszText = "I am a character";
item.iItem = index;
item.iSubItem = 1;
SendMessage(hList, LVM_SETITEM, 0, (LPARAM)&item);

item.mask = LVIF_TEXT;
item.pszText = "24";
item.iItem = index;
item.iSubItem = 2;
SendMessage(hList, LVM_SETITEM, 0, (LPARAM)&item);
</code>

I see the two items and they are in the correct columns. However, if I
click on the item in the second column, I can select it, but the item in the
first column will not select. It's very strange. Is there some other step
that I'm missing?

Thanks again for the quick reply,
Steve



Re: inserting item into list view by Steve

Steve
Tue Nov 22 17:14:24 CST 2005


"David Lowndes" <DavidL@example.invalid> wrote in message
news:lg77o19kpddvu40ei9998d08888l15v2s0@4ax.com...
> >item.mask = LVIF_TEXT|LVIF_;
> >item.pszText = "This is a test";
> >item.iItem = 0;
> >item.iSubItem = 1;
> >SendMessage(hList, LVM_INSERTITEM, 0, (LPARAM)&item);
>
> Steve,
>
> User LVM_INSERTITEM to inset the basic item, use LVM_SETITEMTEXT to
> set any sub-item text. Set iSubItem to 0 for LVM_INSERTITEM.
>
> Dave

Thanks for the reply David, I appreciate it!



Re: inserting item into list view by Igor

Igor
Tue Nov 22 17:20:23 CST 2005

Steve <sss@sss.com> wrote:
> I am much closer now ;)
> But I still have a weird issue.
>
> I see the two items and they are in the correct columns. However, if
> I click on the item in the second column, I can select it, but the
> item in the first column will not select. It's very strange. Is
> there some other step that I'm missing?

You need a column for subitem=0 (the main item). You only add two
columns for subitems 1 and 2.
--
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



Re: inserting item into list view by Steve

Steve
Tue Nov 22 17:32:06 CST 2005


"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eaKGSt77FHA.1140@tk2msftngp13.phx.gbl...
> Steve <sss@sss.com> wrote:
> > I am much closer now ;)
> > But I still have a weird issue.
> >
> > I see the two items and they are in the correct columns. However, if
> > I click on the item in the second column, I can select it, but the
> > item in the first column will not select. It's very strange. Is
> > there some other step that I'm missing?
>
> You need a column for subitem=0 (the main item). You only add two
> columns for subitems 1 and 2.

So although I only want 2, I need to add 3? I'm confused.
subitem index is 1 based, so for the left most column, I would use index 1

I'm trying to understand how this works...

given that I want to have 2 columns visible, do I add 3 columns? I'm sure
this sounds stupid, but I just don't get it




Re: inserting item into list view by Steve

Steve
Tue Nov 22 17:34:32 CST 2005


"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:eaKGSt77FHA.1140@tk2msftngp13.phx.gbl...
> Steve <sss@sss.com> wrote:
> > I am much closer now ;)
> > But I still have a weird issue.
> >
> > I see the two items and they are in the correct columns. However, if
> > I click on the item in the second column, I can select it, but the
> > item in the first column will not select. It's very strange. Is
> > there some other step that I'm missing?
>
> You need a column for subitem=0 (the main item). You only add two
> columns for subitems 1 and 2.


wait, I see. I re-read(again) your post... I understand now, please
disregard my last post. Thank you for your help!