Results 1 to 6 of 6

Thread: Listbox.Clear .Add Methods

  1. #1

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339

    Listbox.Clear .Add Methods

    Much like in VB, I figured I would need to create some fancy listbox functions for C++.


    Here is one I cannot seem to get to work properly.
    PHP Code:
    //------------------
    //Add an item to the list
    //------------------
    void ListBox::AddItem(charItem)
    {
        
    //add string
        
    SendMessage(m_hwndLB_ADDSTRING0, (LPARAM)Item);
        
    SendMessage(m_hwndLB_SETITEMDATAm_IndexCount, (LPARAM)m_IndexCount);
        
    m_IndexCount++;
    }


    //------------------
    //Clear the entire list
    //------------------
    void ListBox::Clear()
    {
        
    LRESULT lRet;
        for (
    int Index 0Index m_IndexCount+1Index++)
        {
            
    lRet SendMessage(m_hwndLB_DELETESTRINGIndex,0);
        }

        
    m_IndexCount 0;

    So I add a bunch of strings using the Add function, then I try and clear it all.

    Well now and then it clears all but one, sometimes all but two depending on how many I add. If it clears all but 1 or 2, or more..then I can just keep pressing it and it gets rid of everything one at a time.

    What is going on????
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  2. #2
    Lively Member
    Join Date
    Jul 2001
    Posts
    81
    Instead of sending an LB_DELETESTRING message for each item, just send an LB_RESETCONTENT message.
    Rate my posts for a chance to win cash and prizes

  3. #3

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    You know, I scoured the list of messages, styles, notifications on MSDN for something like that and I just didn't see it.

    Thank you, it all works fine now.

    RemoveItem, AddItem, Clear...all work
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  4. #4

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Index is always 0...it never incrememnts, shouldnt it?
    MSDN says that particular SendMessage returns the index of the added string.

    PHP Code:
    //------------------
    //Add an item to the list
    //------------------
    void ListBox::AddItem(charItem)
    {
        
    int Index=0;
        
    //add string
        
    Index SendMessage(m_hwndLB_ADDSTRING0, (LPARAM)Item);
        
    SendMessage(m_hwndLB_SETITEMDATAIndex, (LPARAM)Item);

    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    Birmingham, AL
    Posts
    1,276
    Why are you adding an item to the list and then setting the text of the item again? The string would be there after LB_ADDSTRING.

    Are you subclassing? That may be why it returns 0.

  6. #6

    Thread Starter
    PowerPoster Halsafar's Avatar
    Join Date
    Jun 2004
    Location
    Saskatoon, SK
    Posts
    2,339
    Yes I am subclassing, and it was the reason, fixed that part.

    Now wuts wrong the above, I do see setting the string twice...thats just how I saw some code do it so each item had a proper index.

    I guess though I don't really need any item data I found ways around all of that already.
    "From what was there, and was meant to be, but not of that was faded away." - - Steve Damm

    "The polar opposite of nothingness is existance. When existance calls apon nothingness it shall return to nothingness." - - Steve Damm

    "When you do things right, people won't be sure if you did anything at all." - - God from Futurama

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