CHeaderCtrl::SetFocusedItem

Sets the focus to a specified header item in the current header control.

BOOL SetFocusedItem(
     int iItem
);

Parameters

Parameter

Description

[in] iItem

Zero-based index of a header item.

Return Value

true if this method is successful; otherwise, false.

Remarks

This method sends the HDM_SETFOCUSEDITEM message, which is described in the Windows SDK.

Requirements

Header: afxcmn.h

This method is supported in Windows Vista and later.

Additional requirements for this method are described in Build Requirements for Windows Vista Common Controls.

Example

The following code example defines the variable, m_headerCtrl, that is used to access the current header control. This variable is used in the next example.

  CHeaderCtrl m_headerCtrl;
    CSplitButton m_splitButton;

The following code example demonstrates the SetFocusedItem and GetFocusedItem methods. In an earlier section of the code, we created a header control with five columns. However, you can drag a column separator so that the column is not visible. The following example sets and then confirms the last column header as the focus item.

void CNVC_MFC_CHeaderCtrl_s4Dlg::OnXSetfocuseditem()
{
    if (controlCreated == FALSE) {
        MessageBox(_T("Header control has not been created yet."));
        return;
    }

    // Check that we get the value we set. 
    int item = m_headerCtrl.GetItemCount() - 1;
    m_headerCtrl.SetFocusedItem(item);
    int itemGet = m_headerCtrl.GetFocusedItem();
    CString str = _T("Set: focused item = %d\nGet: focused item = %d");
    str.Format(str, item, itemGet);
    MessageBox(str, _T("Set/GetFocused Item"));
}

See Also

Reference

CHeaderCtrl Class

Hierarchy Chart

HDM_SETFOCUSEDITEM

CHeaderCtrl::GetFocusedItem