Link to home
Start Free TrialLog in
Avatar of bs161900
bs161900

asked on

List view control problem

Hi,

I am building a dialog box with 3 edit controls, a list view control in report view and 3 push buttons. With the buttons I want to "Add", "Change" and "Delete" items in the list view control, so for every button I have a button click event handler. See below my event handler for an "Add" button click :

void CBuildShareListDlg::OnAddShareItem()
{
    // Retrieves the following data from the dialog box :
    // CListCtrl    m_lvcShareList;
    // long         m_lVolume;
    // CString      m_strDate;
    // float        m_fRate;
    if ( UpdateData() != TRUE )
        return;
        :
        :
    // Build a CTime object "time" out of m_strDate.

    LV_ITEM      lvItem;
    int          iActItem, iItem;
    TCHAR        szText[3][15];

    lstrcpy( szText[0], ( LPCTSTR ) time.Format( "%d/%m/%Y" ) );
    _stprintf( szText[1], "%f", m_fRate );
    _strprint( szText[2], "%u", ( UINT) m_lVolume );

    iItem = ?  // THAT IS MY PROBLEM.

    for ( int iSubItem = 0; iSubItem < 3; iSubItem++ )
    {
        lvItem.mask = LVIF_TEXT | ( iSubItem == 0 ? LVIF_IMAGE : 0 );
        lvItem.iItem = ( iSubItem == 0 ) ? iItem : iActItem;
        lvItem.iSubItem = iSubItem;
        lvItem.pszText = szText[iSubItem];
        lvItem.iImage = 0;

        if ( iSubItem == 0 )
            ASSERT( ( iActItem = m_lvcShareList.InsertItem( &lvItem ) )!= -1 );
        else
            ASSERT( m_lvcShareList.SetItem( &lvItem ) != -1 );
    }
}

Question 1 :
According to my documentation iItem is a zero based index, but must these indexes be ordered starting from 0 and incremented by 1 each time a new ShareItem is added, or is it just a value that identifies an item in the control.

Question 2 :
When I write my handlers for the "Change" and "Delete" button clicks, how can I figure out which item in the list view is selected. A little bit of code would be very appreciated.


Thanks in advance for everyone that is willing to help me.
ASKER CERTIFIED SOLUTION
Avatar of Answers2000
Answers2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial