Solved

ListControl focus setting

Posted on 2001-08-14
1
355 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

929 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

11 Experts available now in Live!

Get 1:1 Help Now