Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ListControl focus setting

Posted on 2001-08-14
1
Medium Priority
?
377 Views
Last Modified: 2013-11-20
I have an MFC form and on it a command button and a list control. When a user presses the button the list control is populated. I want the first line in the list button to be highlighted.

// I use this line to select all the columns of a row.
ListView_SetExtendedListViewStyle(m_lst,LVS_EX_FULLROWSELECT);
Here is the command button code.

void CTtDlg::OnButton1()
{
CListCtrl* pmyListCtrl = &m_lst;

CString strText;
int nColumnCount = m_lst.GetHeaderCtrl()->GetItemCount();

// Insert 10 items in the list view control.
for (int i=0;i < 10;i++)
{
   strText.Format(TEXT("item %d"), i);

   // Insert the item, select every other item.
   m_lst.InsertItem(
      LVIF_TEXT|LVIF_STATE, i, strText,
      (i%2)==0 ? LVIS_SELECTED : 0, LVIS_SELECTED,
      0, 0);

   // Initialize the text of the subitems.
   for (int j=1;j < nColumnCount;j++)
   {
      strText.Format(TEXT("sub-item %d %d"), i, j);
      m_lst.SetItemText(i, j, strText);
   }

   m_lst.SetItemData (i, i + 3);

}

//Highlight the first item in the list
 m_lst.SetSelectionMark (0);
 m_lst.SetFocus();

Thanks.

jc

}
0
Comment
Question by:jc64
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
xu2000 earned 300 total points
ID: 6387006
Hi,
You can focus Row you want to focus:

m_lst.SetItemState(nRow,
          LVIS_SELECTED | LVIS_FOCUSED ,
          LVIS_SELECTED | LVIS_FOCUSED);
m_lst.EnsureVisible(nRow, FALSE);

Before do that, you can set focus to m_lst and set m_lst style LVS_SHOWSELALWAYS.

Xu
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question