Click to See Complete Forum and Search --> : ListView Control Format and Notification


dro873
February 24th, 2005, 01:44 PM
My program has a dialog box with a listview control in report view which has two columns.

1.) Whenever I create an item and add them to the list-view control via a LVM_INSERTITEM message, it always puts the item in the first (left-most) column. How can I control which column the message is added to?

2.) I want my program to enable a button when the user clicks an item in the listview control. I know that it sends a WM_NOTIFY message with the listview ID in the WPARAM, but what specific notification message does it send (LVN_..., NM_..., etc)?

I know this is a pretty basic question, but msdn is spectacularly vague and it seems all the CodeGuru articles deal with MFC. Thanx for your time.

kirants
February 24th, 2005, 02:24 PM
1.) Whenever I create an item and add them to the list-view control via a LVM_INSERTITEM message, it always puts the item in the first (left-most) column. How can I control which column the message is added to?

That should do it. First you need to LVM_INSERTCOLUMN. Then you need to LVM_INSERTITEM twice, once for the item , once for the subitem.
2.) I want my program to enable a button when the user clicks an item in the listview control. I know that it sends a WM_NOTIFY message with the listview ID in the WPARAM, but what specific notification message does it send (LVN_..., NM_..., etc)?

You'll get a LVN_ITEMCHANGED Notification. The lParam is NMLISTVIEW*.

Note that all common controls send a NMHDR. But they may send more info also. So, in that case, the NMHDR will be the first part of that superstructure. In this case, NMLISTVIEW pointer is passed. If you look at this struct, you will see that it's first part is a NMHDR ( which is the generic structure ) . You may be interested in the iItem and iSubItem members of the NMLISTVIEW struct.

dro873
February 24th, 2005, 03:55 PM
Thanx for the answers. They helped me solve the problems. Btw, you add items using LVM_INSERTITEM, but I think you need to use LVM_SETITEM to add subitems (at least that's how I got it to work).

Thanx again.

kirants
February 24th, 2005, 04:01 PM
That's possible.. I just let my fingers do the typing without thinking much at times ;)