CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Mar 1999
    Posts
    2

    How to get the selected item in a List Ctrl

    Hi,
    I've a CListCtrl derived control embedded in Form View. How do i get the selected item in the list control on a left button click. Note that I can trap the notification message NM_CLICK but how does one proceed from there!!

    TIA
    Sandeep Pendharkar


  2. #2
    Join Date
    Apr 1999
    Posts
    306

    Re: How to get the selected item in a List Ctrl

    Try with CListBox
    it has a member function SetCurSel()
    consider and the other funcs


  3. #3
    Guest

    Re: How to get the selected item in a List Ctrl

    try:
    void xxx::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
    {
    NM_LISTVIEW * pNMListView = (NM_LISTVIEW*) pNMHDR;
    long Index = pNMListView->iItem;
    ...


  4. #4
    Join Date
    May 1999
    Location
    Houston - TX - US
    Posts
    29

    Re: How to get the selected item in a List Ctrl

    HI ,
    try this code !

    void CMyDialog::OnDblclkDitContentsList(NMHDR* pNMHDR, LRESULT* pResult)
    {
    CString SelectedJobID ;
    int Index = 0 ;

    while( 1)
    {
    if ( m_DITContents.GetItemState( Index , LVIS_SELECTED ) == LVIS_SELECTED )
    break ;
    else
    Index++ ;
    }

    // index now gives the selected row .
    // get the Required column say column 4th.
    SelectedJobID = m_DITContents.GetItemText ( Index , 3 ) ;
    ......


    Hope this helps .
    Good Luck.
    Yash.



  5. #5
    Join Date
    Apr 1999
    Posts
    2

    Re: How to get the selected item in a List Ctrl

    Of course this is what you should do

    int index = GetNextItem(-1, LVNI_SELECTED);

    and beware that a message like NM_DBLCLK can be trapped before the item is set as selected, you can get strange behaviour if you select one node (left-click) then dclick on another node, and then get the index of the selected item, it will not be the one you double clicked...

    /Magnus


  6. #6
    Join Date
    Apr 1999
    Posts
    32

    Re: How to get the selected item in a List Ctrl

    CListCtrl::GetFirstSelectedItemPosition
    POSITION GetFirstSelectedItemPosition( ) const;

    CListCtrl::GetItem
    BOOL GetItem( LVITEM* pItem ) const;



    POSITION pos = list.GetFirstSelectedItemPosition( )
    LVITEM lvItem;
    lvItem.iItem = pos;
    list.GetItem(&lvItem);



    (Never tried this, but it seems reasonable.)



    --
    Daren Chandisingh

  7. #7
    Join Date
    May 1999
    Posts
    40

    Re: How to get the selected item in a List Ctrl

    try this.

    CListCtrl::GetNextItem(-1, LVNI_ALL | LVNI_SELECTED)

    hope this help


  8. #8
    Join Date
    Jul 1999
    Posts
    98

    Re: How to get the selected item in a List Ctrl

    If you know the where the item is in the CListCtrl, how do you retrieve the LVITEM struct of it?


  9. #9
    Join Date
    May 1999
    Posts
    60

    Re: How to get the selected item in a List Ctrl

    int nSelected;
    nSelected = m_WndLis.GetNextItem(-1, LVNI_FOCUSED|LVNI_SELECTED);
    if(nSelected==-1)//mean no selected
    else get item no in nSeleceted



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured