CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2011
    Posts
    1

    Help with listbox items

    lets say i have an item in listbox1 with the text "sample" and an item in listbox2 with the text "sample2". How would i make "sample" equal "sample2"?


    Basically i have a directory of a file in listbox2 that is not visable, i want the listbox2 to display some text that equals the same text on the other listbox.

    ~Hope i made sense.

  2. #2
    Join Date
    May 2006
    Location
    Dresden, Germany
    Posts
    458

    Re: Help with listbox items

    Hi,

    using MFC you could do this:

    Code:
    BOOL EqualEntriesInListboxes(CDialog* pDlg, UINT idListBox1, UINT idListBox2)
    {
        if (pDlg)
        {
            CListBox* pLB1 = (CListBox*) pDlg->GetDlgItem(idListBox1);
            CListBox* pLB2 = (CListBox*) pDlg->GetDlgItem(idListBox2);
            if (pLB1 && pLB2)
            {
                pLB2->ResetContent();
                int iCount = pLB1->GetCount();
                if (iCount)
                {
                    int i=0;
                    CString szBuffer;
                    for (i=0; i<iCount; i++)
                    {
                        pLB1->GetText(i, szBuffer);
                        pLB2->AddString(szBuffer);
                    }
                }
                return TRUE;
            }
        }
        return FALSE;
    }
    The function iterates through all the entries of a listbox and adds all entries (strings) to the second listbox.
    Code:
    pLB2->ResetContent();
    is necessary, because otherwise the strings will be added.

    With regards
    PA
    Last edited by ProgramArtist; August 29th, 2011 at 12:57 AM.

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Help with listbox items

    Quote Originally Posted by Rgrant1993 View Post
    same text on the other listbox.

    ~Hope i made sense.
    It didn't to me. ProgramArtist gave you a way to make two listboxes contain identical strings, but it doesn't seem like that's what you're asking.

    Your program would be loading up the listboxes, so why not just load what you want? I'm confused.

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