Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

how to select an item in CListCtrl?

ramib1985ramib1985 Member Posts: 32
I want to select an item in CListCtrl in my OnInitDialog function,I've used SetSelectionMark but it doesn't work .

thanks.

Comments

  • CHRIS_swdevCHRIS_swdev Member Posts: 16
    : I want to select an item in CListCtrl in my OnInitDialog function,I've used SetSelectionMark but it doesn't work .
    :
    : thanks.
    :


    m_LIST.SetCurSel(0);


    //m_LIST.SetCurSel(index that is to be selected);

    I created m_LIST in class wizard
    m_LIST is of type clistbox control

    That should do the trick
    ~Chris
  • dwccgcdwccgc Member Posts: 576
    : : I want to select an item in CListCtrl in my OnInitDialog function,I've used SetSelectionMark but it doesn't work .
    : :
    : : thanks.
    : :
    :
    :
    : m_LIST.SetCurSel(0);
    :
    :
    : //m_LIST.SetCurSel(index that is to be selected);
    :
    : I created m_LIST in class wizard
    : m_LIST is of type clistbox control
    :
    : That should do the trick
    : ~Chris
    :
    [blue]
    I believe SetCurSel() is not a member function of CListCtrl.

    Try this
    [/blue]
    [code]
    LVITEM lvi;
    ZeroMemory(&lvi, sizeof(lvi));
    lvi.mask = LVIF_STATE;
    lvi.state = LVIS_SELECTED;
    lvi.stateMask = LVIS_SELECTED;
    // Idx is the Item you want to select
    // Idx = -1 will clear all selections
    myListCtrl.SetItemState(Idx, &lvi);
    [/code]

    [blue]
    You can go to msdn.microsoft.com to get more information on LVITEM and CListCtrl.
    [/blue]

Sign In or Register to comment.