CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Guest

    ***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!!!!!!!!!!!!!


  2. #2
    Join Date
    Apr 1999
    Posts
    3

    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());


  3. #3
    Join Date
    Apr 1999
    Location
    Norway
    Posts
    19

    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


  4. #4
    Join Date
    Apr 1999
    Posts
    383

    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


  5. #5
    Join Date
    Apr 1999
    Location
    Quebec, Canada
    Posts
    39

    Re: ***ListCtrl.pszText = szItem as CString***

    Hi,

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


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