Can anyone share an idea or some sample code on how I can highlight a row
inside a CListCtrl, as though the user had clicked the mouse pointer on the
specified row?
Any help would be greatly appreciated, and I'll gladly post any findings.
Thank you in advance for your time and help...
--
Bill Wonneberger
wbe...@locke.ccil.org
www.ccil.org/~wberger/
using yourListCtrl.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
yourListCtrl.Update(nItem);
Yong
...
>
> using yourListCtrl.SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED);
> yourListCtrl.Update(nItem);
>
...
Thanks for the suggestion Yong, but I couldn't get this to work.
CListCtrl::SetItemState() does change what the CListCtrl keeps as the index
of the selected list item, but it doesn't highlight the selected item.
Since Update is in the CWnd base class, I also tried using UpdateWindow(),
but like your previous suggestion, I couldn't get it to work either.
There is one thing I forgot to mention in my original posting. The
CListCtrl instance in my application is my own CListCtrl derived object,
which highlights the entire row of the list control when it's in report
mode. This method is described in the Microsoft KB article Q230049. In my
derived class, I've overridden the CListCtrl implementation of
CListCtrl::OnCreate() using the following;
int CRowSelListCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
TRACE("\n\n Entering CRowSelListCtrl::OnCreate()\n");
if (CListCtrl::OnCreate(lpCreateStruct) == -1)
return -1;
DWORD dwStyle = ::SendMessage(m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE,
0, 0);
dwStyle |= LVS_EX_FULLROWSELECT;
::SendMessage(m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
TRACE("\n Leaving CRowSelListCtrl::OnCreate()\n\n");
return 0;
}
Would this keep either Update() or UpdateWindow() from highlighting the
specified row? Or, am I missing something else?
Thanks again for your time and help. Any additional ideas or insights would
be greatly appreciated.
myListCtrl.SetItemState(nNewSelection, LVIS_SELECTED | LVIS_FOCUSED,
0x000F);
--
----
Chris Scott
SnoopSoft Corporation
http://www.snoopsoft.com
William Wonneberger <wbe...@locke.ccil.org> wrote in message
news:ut$aptnG$GA.251@cppssbbsa05...
> Greetings;
>
> Can anyone share an idea or some sample code on how I can highlight a row
> inside a CListCtrl, as though the user had clicked the mouse pointer on
the
> specified row?
>
Try youListCtrl.SetFocus()
Or if you don't want to set your control to focus, you may need to set the
following style when your create your list control:
LVS_SHOWSELALWAYS
Yong.
First and foremost, my sincerest thanks to everyone who helped.
I did get the following to work;
m_iListIndex = m_lstMyList.FindItem(&lvfSearch, m_iListIndex);
if(m_iListIndex != -1)
{
m_lstMyList.SetItemState(m_iListIndex, LVIS_SELECTED |
LVIS_FOCUSED, 0x000F);
m_lstMyList.EnsureVisible(m_iListIndex, FALSE);
}
And to "deselect" a selected item....
if(m_iListIndex != -1)
{
uState = m_lstMyList.GetItemState(m_iListIndex, LVIS_SELECTED);
if(uState)
m_lstMyList.SetItemState(m_iListIndex, 0, LVIS_SELECTED);
}
The call of CListCtrl::SetItemState() as shown in the first highlighting
code fragement was courtesy of Chris Scott at SnoopSoft Corporation. I am
also glad that a similar solution I received from Vaughn Arthur included
CListCtrl::EnsureVisible(), which I originally overlooked in going through
the MFC CListCtrl class member documentation. CListCtrl::EnsureVisible()
will scroll the list control focus to the specified item if it isn't already
visible. I also received a number of suggestions from Yong Zhao which also
helped shed some light on my coding problem.
Again, many thanks to Chris Scott, Vaughn Arthur, and Yong Zhao for their
time and help...
Best Regards...