have you even run into problem like this?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: have you even run into problem like this?

  1. #1
    Join Date
    Jul 2004
    Location
    Scotland
    Posts
    143

    Talking have you even run into problem like this?

    Just use a listctrl in my view, and when I insert item like this, the data won't be able to display multiple rows of data correctly

    Code:
         this->m_ListCtrl.InsertItem(i,name,0);
         s.Format("%s",name);
         this->m_ListCtrl.SetItemText(i,0,s);
    there are several item block has no text displayed in the listctrl at all.
    but if you change format line into
    Code:
    s.Format(" %s",name);
    by adding an extra space in front of the %s, it will work. Wondering why...

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,418
    It looks like your problem is in sorting style of your list control.
    Either change this style to NONE (in resource editor)
    or (the best way for you)
    correct your code:
    Code:
         int iItem = this->m_ListCtrl.InsertItem(i,name,0);
         if(iItem > -1)
         {
              s.Format("%s",name);
              this->m_ListCtrl.SetItemText(iItem,0,s);
         }

  3. #3
    Join Date
    Sep 2002
    Location
    14 39'19.65"N / 121 1'44.34"E
    Posts
    9,815
    A few things:
    • Why are you using this-> when accessing m_ListCtrl? You don't need that, just write m_ListCtrl.
    • Why are you using Format("%s") to assign a string to another? Just assign it with s = name. To add a blank, write s = " " + name;
    • When adding an item with InsertItem(), you can specify an item index. However, this is just a request, it is not guaranteed that the item will be inserted at that position. That's why InsertItem() returns the actual item index, and you should use that in your call to SetItemText(), not your original index. Especially when the list control is sorted, the index will differ from the one you supplied, so I suspect that this is your actual problem.

  4. #4
    Join Date
    Jul 2004
    Location
    Scotland
    Posts
    143

    habit from Java

    I just thinking java when programming in VC, so that's why I like to use this pointer to avoid ambiguity.

    no point using format , but I am just curious.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center