点击ComboBox弹出列表框时,正常情况下,
鼠标在列框框中移动会自动选中鼠标下面的项,
或者用方向键上下键也能使选中的项上下移动。而我的需求是不用鼠标,也不用键盘,
直接需要用代码控制选中第 n 项。
要求选中这第n项后,ComboBox上面的文本框或组合框内容保持不变,
就是说效果要与鼠标移动到那一项相同(但鼠标可以不在那个位置)。
如何实现这个功能?

解决方案 »

  1.   

    Microsoft Foundation Class Library for Windows CE   CComboBox::SetCurSelSee Also
    CComboBox::GetCurSel 
    Requirements
    Windows CE versions: 1.0 and later
    Header file: Declared in Afxwin.h
    This method selects a string in the list box of a combo box. If necessary, the list box scrolls the string into view. The text in the edit control of the combo box is changed to reflect the new selection. Any previous selection in the list box is removed.int SetCurSel( 
    int nSelect ); 
    Parameters
    nSelect 
    Specifies the zero-based index of the string to select. If –1, any current selection in the list box is removed and the edit control is cleared. 
    Return Value
    The zero-based index of the item selected if the message is successful. The return value is CB_ERR if nSelect is greater than the number of items in the list or if nSelect is set to –1, which clears the selection.Example// The pointer to a combo box.
    extern CComboBox* pmyComboBox;// Select the last item in the combo box.
    int nCount = pmyComboBox->GetCount();
    if (nCount > 0)
      pmyComboBox->SetCurSel(nCount-1);
    Requirements
    Windows CE versions: 1.0 and later
    Header file: Declared in Afxwin.hSee Also
    CComboBox::GetCurSel --------------------------------------------------------------------------------Send feedback on this topic to Microsoft© Microsoft Corporation. All rights reserved.Topic Version 7.1.2277.1013
      

  2.   

    SetCurSel是选中某行,GetCurSel是获取选中某行,
    使用SetCurSel后,ComboBox上面的文本框(DropDown风格)内容将被改写,
    而我需要的是下面的列表框选中希望的行,而文本框仍然显示以前的内容。