Solved

ListControl focus setting

Posted on 2001-08-14
1
352 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
1 Comment
 
LVL 2

Accepted Solution

by:
xu2000 earned 75 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now