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

    Visual c++ : how to create dinamic number of edit boxes

    I've created a simple dialog box program in standard Visual c++ (2005 not .net)

    the first Dialog ask : How many Edit Boxes do you want to create ?

    the user inserts a number, and in the next dialog the user will have the edit boxes.

    So how can i create a random number of Edit Boxes and how can i associate the ID to work with the code ?

    Does anyone have an example to create a random number of Edit Boxes, and how can i associate their own random ID ??

  2. #2
    Join Date
    Nov 2010
    Location
    CA
    Posts
    29

    Re: Visual c++ : how to create dinamic number of edit boxes

    This sounds similar to what my friend needed to create a dynamic menu that can change during run-time.

    He used what he called pure virtual functions.

    Unfortunately, I'm still just learning, so I don't have the experience to give you an example, or describe it in any greater detail, but I hope this points you in the right direction.

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual c++ : how to create dinamic number of edit boxes

    Are you interested in retrieving the text data from each edit box, or will displaying the edit boxes be enough for your needs?

  4. #4
    Join Date
    Apr 2009
    Posts
    598

    Re: Visual c++ : how to create dinamic number of edit boxes

    Try:
    Code:
    #define MAX_ED 100
    HWND hwnd_ed[MAX_ED];
    int x, y, w, h;
    x = 10; y = 10; w = 80; h = 20;
    for (i_ed = 0; i_ed < nb_ed && i_ed < MAX_ED; i_ed++) {
       hwnd_ed[i_ed] = CreateWindowEx(WS_EX_CLIENTEDGE, "edit", "",
                                  WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER | ES_LEFT,
                                  x, y, w, h,
                                  hwnd, (HMENU)(1000 + i_ed),
                                  (HINSTANCE) GetWindowLong (hwnd, GWL_HINSTANCE), NULL);
      y += h +2;
    }

  5. #5
    Join Date
    Nov 2010
    Posts
    3

    Re: Visual c++ : how to create dinamic number of edit boxes

    Yes, i need to retrieve the text data from each edit box...so i'm wondering what is a solution to do this...( can i use an array to store all the values from each edit box ?? )

    1. ask how many edit boxes
    2. the user insert the number
    3. the new window display the exact number of edit boxes
    4. the user insert values in the edit boxes
    5. the software retrieves all the values and ..go on...

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual c++ : how to create dinamic number of edit boxes

    Last question...

    How many of these edit boxes would you like to display?

  7. #7
    Join Date
    Nov 2010
    Posts
    3

    Re: Visual c++ : how to create dinamic number of edit boxes

    I do not think it is an important data, but i think up to 30...it depends on user insert...
    Theese will be small edit boxes that must contain only up to six digits

  8. #8
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Visual c++ : how to create dinamic number of edit boxes

    Why not make a dialog template with all the edits you will ever need. Then programmatically remove the WS_VISIBLE style off from the ones you don't want to see.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Visual c++ : how to create dinamic number of edit boxes

    What I would do is use a virtual List control to display a two column view of a label (in the 1st column) and the data (in the 2nd column).

    When the user double clicks on the 2nd column an edit box appears in the selected row of the 2nd column.

    The data for each row would be stored in an STL collection which the virtual list control gets bound to.

    See the following link for the LVEdit2005.zip attachment for the sample code that does what I described.

    http://www.codeguru.com/forum/showthread.php?t=440228

    Sample in row edit mode...
    Attached Images Attached Images  

Tags for this Thread

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