How to highlight selected item on CListCtrl

How to highlight selected item on CListCtrl

Post by Jae-Young Su » Tue, 17 Dec 1996 04:00:00



Dear VC++ Experts,

Is there anyone who can tell me how to highlight the selected
item on CListCtrl ?

I have created a list containing several columns. When I
click a first column of list it gets highlighted but it
doesn't get highlighted when I click second, third, fourth ... column
of list. I want to highlight whole rows of list where ever I
click, as long as the mouse position is on the same row.

Please tell me how.

Thanks,

Jae-Young Suh

 
 
 

How to highlight selected item on CListCtrl

Post by Rob Warne » Tue, 17 Dec 1996 04:00:00


This does half of what you want; it allows you to click on any column in
the row to select, but still just highlights the first item.  It's a start,
though :)

void CAsciiListCtrl::OnClick(NMHDR* pNMHDR, LRESULT* pResult)
{
    // Get the current mouse location and convert it to client
    // coordinates.
    DWORD dwPos = GetMessagePos();
    CPoint pt(LOWORD(dwPos), HIWORD(dwPos));
    ScreenToClient(&pt);

    // Get indexes of the first and last visible items in listview
    // control.
    int nIndex = GetTopIndex();
    int nLast = nIndex + GetCountPerPage();
    nLast = (nLast > GetItemCount() ? GetItemCount() : nLast);

    // Loop until number visible items has been reached.
    while (nIndex <= nLast)
    {
        // Get the bounding rectangle of an item. If the mouse
        // location is within the bounding rectangle of the item,
        // you know you have found the item that was being clicked.
        CRect rect;
        GetItemRect(nIndex, &rect, LVIR_BOUNDS);
        if (rect.PtInRect(pt))
        {
            UINT nFlags = LVIS_SELECTED | LVIS_FOCUSED;
            SetItemState(nIndex, nFlags, nFlags);
            break;
        }

        // Get the next item in listview control.
        ++nIndex;
    }
    *pResult = 0;

Quote:}

--
Rob Warner

http://users.southeast.net/~rhwarner



Quote:> Dear VC++ Experts,

> Is there anyone who can tell me how to highlight the selected
> item on CListCtrl ?

> I have created a list containing several columns. When I
> click a first column of list it gets highlighted but it
> doesn't get highlighted when I click second, third, fourth ... column
> of list. I want to highlight whole rows of list where ever I
> click, as long as the mouse position is on the same row.

> Please tell me how.

> Thanks,

> Jae-Young Suh


 
 
 

How to highlight selected item on CListCtrl

Post by Yudong Su » Tue, 17 Dec 1996 04:00:00


I belive there's an MFC sample that does exactly what you want.
Check it out from your VC++ CD.

Yudong


> Dear VC++ Experts,

> Is there anyone who can tell me how to highlight the selected
> item on CListCtrl ?

> I have created a list containing several columns. When I
> click a first column of list it gets highlighted but it
> doesn't get highlighted when I click second, third, fourth ... column
> of list. I want to highlight whole rows of list where ever I
> click, as long as the mouse position is on the same row.

> Please tell me how.

> Thanks,

> Jae-Young Suh

 
 
 

1. CListCtrl Highlighted item

I've got a CListCtrl in a dialog box in report mode. If I select an item in
the list it is highlighted. If I click on an edit box elsewhere in the
dialog box the highlighting in the CListCtrl goes away.

Anyone have any ideas how I might prevent that?

The list shows a number of items. You select an item from the list, and I
fill in a bunch of edit controls in the same dialog with the parameters
associated with the selected item. This works great. But if you click on one
of the edit fields to change the parameter, the highlighting goes away in
the list. It is easy to forget which item's parameters you are editing
without the highlighting in the list.

Thanks,
Buzz

2. Can.Multimedia Companies

3. Hiding selected item in CListCtrl

4. An introduction to multimedia movie-making

5. CListCtrl doesn't keep item selected

6. NT On-Access Scanner Service

7. Select an item in a CListCtrl

8. Quick launch icons

9. CListCtrl: how to know when no item is selected?

10. Programatically selecting CListCtrl items.

11. How to get index of selected item in a CListCtrl ?

12. How can I get the selected item in a CListCtrl?

13. How to Programmatically set a CListCtrl item SELECTED | FOCUSED