Click to See Complete Forum and Search --> : ***ListCtrl.pszText = szItem as CString***


April 18th, 1999, 12:37 AM
Hi,
I am making a program that uses CListView as its main view. I am using: lvi.pszText = szItem; to add text to the items I insert into it.
The computer will only let me use a char value for szItem, but I need it as a CString because all the values I want to pass to it are CString values!!!!
Are there any ways to make a ListView item text a CString value or to convert a CString to char????
Thanks ALOT!!!!!!!!!!!!!

Srinath Salvadhi
April 18th, 1999, 04:01 AM
Extract the string using the operator LPCTSTR of CString, and copy the same into pszText of lv_item s
structure.
Sample Code:
CString cItemText ;
// get the item text.
lstrcpy(ListCtrl.pszText, cItemText.opeartor LPCTSTR());

Hussam
April 19th, 1999, 06:31 AM
The easiest and best way is to do this

CString str = "your value";
for each Item you add you just call this
item.pszText = str.GetBuffer(0);

Hussam

Dave Lorde
April 19th, 1999, 07:07 AM
Don't do what Srinath suggests and copy the string into the pszText of the lv_item(s), because the pszText expects the *address* of a string, and unless you have already initialized pszText to point to an allocated buffer in memory, your program will probably crash.

The GetBuffer() solution is better.

Dave

Nath
April 21st, 1999, 01:45 PM
Hi,

I just do
CString text;
ListCtrl.pszText = (LPCSTR)text;
and it works.
Nath.