Thread: LB_GETTEXT listbox command

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    26

    LB_GETTEXT listbox command

    I am trying to read in the text of all items in a listbox and copy that text to an edit box (text box). However when I do, the string that is suppose to store all the items of the listbox only stores the last item that was read in. Here is my code:

    Code:
    int i, a;
    char etxt[100];
    
    i = SendMessage(hList, LB_GETCOUNT, 0, 0); //gets the number of items in listbox
    for (a=0; a<i; a++)
    {
      SendMessage(hList, LB_GETTEXT, a, etxt); //get all text
     }
    
     SetDlgItemText(hwnd, ED_Box, etxt); //set the edit box to contain the string
    So the problem is that the string etxt only contains the last item that was read in from the listbox, when it should contain all items.

    Any ideas?

  2. #2
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by Brigs76
    I am trying to read in the text of all items in a listbox and copy that text to an edit box (text box). However when I do, the string that is suppose to store all the items of the listbox only stores the last item that was read in. Here is my code:

    Code:
    int i, a;
    char etxt[100];
    
    i = SendMessage(hList, LB_GETCOUNT, 0, 0); //gets the number of items in listbox
    for (a=0; a<i; a++)
    {
      SendMessage(hList, LB_GETTEXT, a, etxt); //get all text
     }
    
     SetDlgItemText(hwnd, ED_Box, etxt); //set the edit box to contain the string
    So the problem is that the string etxt only contains the last item that was read in from the listbox, when it should contain all items.

    Any ideas?
    instead of copy pasting that code you should try to understand it
    had this little line to your better understading...

    Code:
    int i, a;
    char etxt[100];
    
    i = SendMessage(hList, LB_GETCOUNT, 0, 0); //gets the number of items in listbox
    for (a=0; a<i; a++)
    {
      SendMessage(hList, LB_GETTEXT, a, etxt); //get all text
      printf("line at %d - %s\n",a,etxt);
     }
    
     SetDlgItemText(hwnd, ED_Box, etxt); //set the edit box to contain the string

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    26
    Quote Originally Posted by xErath
    instead of copy pasting that code you should try to understand it
    had this little line to your better understading...

    Code:
    int i, a;
    char etxt[100];
    
    i = SendMessage(hList, LB_GETCOUNT, 0, 0); //gets the number of items in listbox
    for (a=0; a<i; a++)
    {
      SendMessage(hList, LB_GETTEXT, a, etxt); //get all text
      printf("line at %d - %s\n",a,etxt);
     }
    
     SetDlgItemText(hwnd, ED_Box, etxt); //set the edit box to contain the string
    that line does nothing for me as I am making a windows program, not dos, so the printf does not output anything.

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    I am making a windows program, not dos, so the printf does not output anything.
    Opps.

    Open a file and use fprintf(), then look at the file afterwards.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 09:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 12:54 PM
  5. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 04:36 PM