***ListCtrl.pszText = szItem as CString***
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!!!!!!!!!!!!!
Re: ***ListCtrl.pszText = szItem as CString***
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());
Re: ***ListCtrl.pszText = szItem as CString***
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
Re: ***ListCtrl.pszText = szItem as CString***
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
Re: ***ListCtrl.pszText = szItem as CString***
Hi,
I just do
CString text;
ListCtrl.pszText = (LPCSTR)text;
and it works.
Nath.