WTL CListViewCtrl 
Author Message
 WTL CListViewCtrl

Hello,

I'm stuck at populating a simple listview. It should be rather easy, but I
never worked with those before, can't find any samples anywhere and so I am
about to lose my nerves.

My class definition should be alright:
class ULineView : public CWindowImpl<ULineView, CListViewCtrl>

I am successfully displaying two columns using in OnCreate
AddColumn("Device", 0);
AddColumn("ID", 1);

Now how can I populate rows? I'm rather confused with items, subitems, all
types of strings you can set, tried a lot, never had anything displayed.

Can you show me the required piece of code?

Thanks a lot!
Gerhard



Tue, 01 Mar 2005 02:41:08 GMT  
 WTL CListViewCtrl
See AddItem, InsertItem, SetItem. nItem parameter is the row number,
nSubItem is column number. You must set the item at column 0 before you
can add strings to other columns of the same row.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:
> Hello,

> I'm stuck at populating a simple listview. It should be rather easy,
but I
> never worked with those before, can't find any samples anywhere and so
I am
> about to lose my nerves.

> My class definition should be alright:
> class ULineView : public CWindowImpl<ULineView, CListViewCtrl>

> I am successfully displaying two columns using in OnCreate
> AddColumn("Device", 0);
> AddColumn("ID", 1);

> Now how can I populate rows? I'm rather confused with items, subitems,
all
> types of strings you can set, tried a lot, never had anything
displayed.

> Can you show me the required piece of code?

> Thanks a lot!
> Gerhard



Tue, 01 Mar 2005 03:58:12 GMT  
 WTL CListViewCtrl



Quote:
> See AddItem, InsertItem, SetItem. nItem parameter is the row number,
> nSubItem is column number. You must set the item at column 0 before you
> can add strings to other columns of the same row.
> --
> With best wishes,
>     Igor Tandetnik

Here is one of my (not working) tries:

LRESULT ULineView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
/*lParam*/, BOOL& bHandled)
{
AddColumn("Device", 0);
AddColumn("ID", 1);

LVITEM i1;
i1.mask = LVIF_TEXT;
i1.pszText = "showMe";
i1.iItem = 0;
i1.iSubItem = 1;
SetItem(&i1);

LVITEM i2;
i2.mask = LVIF_TEXT;
i2.pszText = "please";
i2.iItem = 0;
i2.iSubItem = 2;
SetItem(&i2);

bHandled = false;
return 0;

Quote:
}

What am I missing or doing wrong?
Thank you!
Gerhard


Tue, 01 Mar 2005 04:46:29 GMT  
 WTL CListViewCtrl
SetItem changes the settings for existing item. Before you can use it,
you need to add a new item, with AddItem or InsertItem.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:



> > See AddItem, InsertItem, SetItem. nItem parameter is the row number,
> > nSubItem is column number. You must set the item at column 0 before
you
> > can add strings to other columns of the same row.
> > --
> > With best wishes,
> >     Igor Tandetnik

> Here is one of my (not working) tries:

> LRESULT ULineView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
> /*lParam*/, BOOL& bHandled)
> {
> AddColumn("Device", 0);
> AddColumn("ID", 1);

> LVITEM i1;
> i1.mask = LVIF_TEXT;
> i1.pszText = "showMe";
> i1.iItem = 0;
> i1.iSubItem = 1;
> SetItem(&i1);

> LVITEM i2;
> i2.mask = LVIF_TEXT;
> i2.pszText = "please";
> i2.iItem = 0;
> i2.iSubItem = 2;
> SetItem(&i2);

> bHandled = false;
> return 0;
> }

> What am I missing or doing wrong?
> Thank you!
> Gerhard



Tue, 01 Mar 2005 05:15:14 GMT  
 WTL CListViewCtrl



Quote:
> SetItem changes the settings for existing item. Before you can use it,
> you need to add a new item, with AddItem or InsertItem.
> --

I replaced SetItem with InsertItem to no result:

LRESULT ULineView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
/*lParam*/, BOOL& bHandled)
{
AddColumn("Device", 0);
AddColumn("ID", 1);

LVITEM i1;
i1.mask = LVIF_TEXT;
i1.pszText = "showMe";
i1.iItem = 0;
i1.iSubItem = 1;
InsertItem(&i1);

LVITEM i2;
i2.mask = LVIF_TEXT;
i2.pszText = "please";
i2.iItem = 0;
i2.iSubItem = 2;
InsertItem(&i2);

bHandled = false;
return 0;

Quote:
}

Yesterday I successfully developed a strategy to get out that evil deadlock
of my multithreading application, today I fail to insert items into a list.
Quite the same level ;)

I'm glad that you help me, thank you! Do you have one more hint?



Tue, 01 Mar 2005 05:45:59 GMT  
 WTL CListViewCtrl
As I said, you need to insert something under subitem 0 (leftmost
column) before you can add to other columns. Inserting in subItem 0
creates a new row, inserting into other subitems fails if the row does
not already exist.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:



> > SetItem changes the settings for existing item. Before you can use
it,
> > you need to add a new item, with AddItem or InsertItem.
> > --

> I replaced SetItem with InsertItem to no result:

> LRESULT ULineView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
> /*lParam*/, BOOL& bHandled)
> {
> AddColumn("Device", 0);
> AddColumn("ID", 1);

> LVITEM i1;
> i1.mask = LVIF_TEXT;
> i1.pszText = "showMe";
> i1.iItem = 0;
> i1.iSubItem = 1;
> InsertItem(&i1);

> LVITEM i2;
> i2.mask = LVIF_TEXT;
> i2.pszText = "please";
> i2.iItem = 0;
> i2.iSubItem = 2;
> InsertItem(&i2);

> bHandled = false;
> return 0;
> }

> Yesterday I successfully developed a strategy to get out that evil
deadlock
> of my multithreading application, today I fail to insert items into a
list.
> Quite the same level ;)

> I'm glad that you help me, thank you! Do you have one more hint?



Tue, 01 Mar 2005 05:59:50 GMT  
 WTL CListViewCtrl



Quote:
> As I said, you need to insert something under subitem 0 (leftmost
> column) before you can add to other columns. Inserting in subItem 0
> creates a new row, inserting into other subitems fails if the row does
> not already exist.
> --

Of course I did also already try the following among lots of other things
which all yielded no results:

LRESULT ULineView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
/*lParam*/, BOOL& bHandled)
{
AddColumn("Device", 0);
AddColumn("ID", 1);

LVITEM i1;
i1.mask = LVIF_TEXT;
i1.pszText = "showMe";
i1.iItem = 0;
i1.iSubItem = 0;
InsertItem(&i1);

LVITEM i2;
i2.mask = LVIF_TEXT;
i2.pszText = "please";
i2.iItem = 0;
i2.iSubItem = 1;
InsertItem(&i2);

bHandled = false;
return 0;

Quote:
}

There must be something else missing?

Gerhard



Tue, 01 Mar 2005 06:31:11 GMT  
 WTL CListViewCtrl
Change the second call to SetItem, instead of InsertItem. Works for me.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:



> > As I said, you need to insert something under subitem 0 (leftmost
> > column) before you can add to other columns. Inserting in subItem 0
> > creates a new row, inserting into other subitems fails if the row
does
> > not already exist.
> > --

> Of course I did also already try the following among lots of other
things
> which all yielded no results:

> LRESULT ULineView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
> /*lParam*/, BOOL& bHandled)
> {
> AddColumn("Device", 0);
> AddColumn("ID", 1);

> LVITEM i1;
> i1.mask = LVIF_TEXT;
> i1.pszText = "showMe";
> i1.iItem = 0;
> i1.iSubItem = 0;
> InsertItem(&i1);

> LVITEM i2;
> i2.mask = LVIF_TEXT;
> i2.pszText = "please";
> i2.iItem = 0;
> i2.iSubItem = 1;
> InsertItem(&i2);

> bHandled = false;
> return 0;
> }

> There must be something else missing?

> Gerhard



Tue, 01 Mar 2005 22:18:57 GMT  
 WTL CListViewCtrl



Quote:
> Change the second call to SetItem, instead of InsertItem. Works for me.
> --
> With best wishes,
>     Igor Tandetnik

Not for me though :(

Created an application Listview with the App-Wizard, selected listview.
Added the WM_CREATE Handler. Placed the following code there:

LRESULT CListviewView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM
/*lParam*/, BOOL& bHandled)
{
AddColumn("Device", 0);
AddColumn("ID", 1);

LVITEM i1;
i1.mask = LVIF_TEXT;
i1.pszText = "showMe";
i1.iItem = 0;
i1.iSubItem = 0;
InsertItem(&i1);

LVITEM i2;
i2.mask = LVIF_TEXT;
i2.pszText = "please";
i2.iItem = 0;
i2.iSubItem = 1;
SetItem(&i2);
bHandled = false;

return 0;

Quote:
}

That's all I did. Could you perhaps send me a working example so I can
figure out whats wrong with mine? That would be really nice!
Thanks again for any help

Gerhard



Wed, 02 Mar 2005 02:12:46 GMT  
 WTL CListViewCtrl
It works for me this way:

LRESULT CListviewView::OnCreate(UINT uMsg, WPARAM wParam, LPARAM
lParam, BOOL& bHandled)
{
 DefWindowProc(uMsg, wParam, lParam);

 AddColumn("Device", 0);
 AddColumn("ID", 1);

 LVITEM i1 = {0};
 i1.mask = LVIF_TEXT;
 i1.pszText = "showMe";
 i1.iItem = 0;
 i1.iSubItem = 0;
 InsertItem(&i1);

 LVITEM i2;
 i2.mask = LVIF_TEXT;
 i2.pszText = "please";
 i2.iItem = 0;
 i2.iSubItem = 1;
 SetItem(&i2);

 bHandled = true;

 return 0;

Quote:
}

I guess forwarding WM_CREATE to default processing before adding
elements was the missing piece.
--
With best wishes,
    Igor Tandetnik

"For every complex problem, there is a solution that is simple, neat,
and wrong." H.L. Mencken


Quote:



> > Change the second call to SetItem, instead of InsertItem. Works for
me.
> > --
> > With best wishes,
> >     Igor Tandetnik

> Not for me though :(

> Created an application Listview with the App-Wizard, selected
listview.
> Added the WM_CREATE Handler. Placed the following code there:

> LRESULT CListviewView::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/,
LPARAM
> /*lParam*/, BOOL& bHandled)
> {
> AddColumn("Device", 0);
> AddColumn("ID", 1);

> LVITEM i1;
> i1.mask = LVIF_TEXT;
> i1.pszText = "showMe";
> i1.iItem = 0;
> i1.iSubItem = 0;
> InsertItem(&i1);

> LVITEM i2;
> i2.mask = LVIF_TEXT;
> i2.pszText = "please";
> i2.iItem = 0;
> i2.iSubItem = 1;
> SetItem(&i2);
> bHandled = false;

> return 0;
> }

> That's all I did. Could you perhaps send me a working example so I can
> figure out whats wrong with mine? That would be really nice!
> Thanks again for any help

> Gerhard



Wed, 02 Mar 2005 03:22:00 GMT  
 WTL CListViewCtrl

Quote:
> I guess forwarding WM_CREATE to default processing before adding
> elements was the missing piece.
> --
> With best wishes,
>     Igor Tandetnik

You are right, it works now! That was hard ;)

Thank you very much for all your help!
Gerhard



Wed, 02 Mar 2005 03:42:41 GMT  
 
 [ 11 post ] 

 Relevant Pages 

1. WTL & CListViewCtrl

2. WTL - Very new to WTL - Trying to insert new COM object in WTL

3. CListViewCtrl and DragAndDrop

4. Change Image in CListViewCtrl

5. Superclassing CListViewCtrl (ATL)

6. Flicker during resize in CListViewCtrl

7. OnPaint override on CListViewCtrl?

8. Deleting Selected items in CListViewCtrl

9. CListViewCtrl

10. How to get FullRowSelect to select whole row in CListViewCtrl

11. Wrapping column headers in CListViewCtrls

12. CListViewCtrl stupid question

 

 
Powered by phpBB® Forum Software