Udostępnij za pośrednictwem


CListBox::GetText

Gets a string from a list box.

int GetText( 
   int nIndex, 
   LPTSTR lpszBuffer  
) const; 
void GetText( 
   int nIndex, 
   CString& rString  
) const;

Parameters

  • nIndex
    Specifies the zero-based index of the string to be retrieved.

  • lpszBuffer
    Points to the buffer that receives the string. The buffer must have sufficient space for the string and a terminating null character. The size of the string can be determined ahead of time by calling the GetTextLen member function.

  • rString
    A reference to a CString object.

Return Value

The length (in bytes) of the string, excluding the terminating null character. If nIndex does not specify a valid index, the return value is LB_ERR.

Remarks

The second form of this member function fills a CString object with the string text.

Example

// Dump all of the items in the list box.
CString str, str2;
int n;
for (int i = 0; i < m_myListBox.GetCount(); i+)
{
   n = m_myListBox.GetTextLen(i);
   m_myListBox.GetText(i, str.GetBuffer(n));
   str.ReleaseBuffer();

   str2.Format(_T("item %d: %s\r\n"), i, str.GetBuffer(0));
   AFXDUMP(str2);
}

Requirements

Header: afxwin.h

See Also

Reference

CListBox Class

Hierarchy Chart

CListBox::GetTextLen

LB_GETTEXT

Other Resources

CListBox Members