jc64
asked on
ListControl focus setting
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_SetExtendedListVi ewStyle(m_ lst,LVS_EX _FULLROWSE LECT);
Here is the command button code.
void CTtDlg::OnButton1()
{
CListCtrl* pmyListCtrl = &m_lst;
CString strText;
int nColumnCount = m_lst.GetHeaderCtrl()->Get ItemCount( );
// 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-i tem %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
}
// I use this line to select all the columns of a row.
ListView_SetExtendedListVi
Here is the command button code.
void CTtDlg::OnButton1()
{
CListCtrl* pmyListCtrl = &m_lst;
CString strText;
int nColumnCount = m_lst.GetHeaderCtrl()->Get
// 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-i
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
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.