?
Solved

ListControl focus setting

Posted on 2001-08-14
1
Medium Priority
?
373 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

770 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