Share via


CHeaderCtrl::GetFocusedItem

Gets the index of the item that has the focus in the current header control.

int GetFocusedItem() const;

Return Value

The zero-based index of the header item that has the focus.

Remarks

This method sends the HDM_GETFOCUSEDITEM 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_GETFOCUSEDITEM

CHeaderCtrl::SetFocusedItem

Other Resources

CHeaderCtrl Members