hi ,
i have a very simple Family tree project using GUI.....
and i have two forms !
the first form ask the user to enter the number of child the parent have then in the 2nd form there will be a box as the number of child
like when i enter 3 in form1!
in form 2 should be 3 box to fill up the children names ? how to do that ??

Dani AI

Generated

As described, the task is to have Form1 collect a number and have Form2 present that many name fields. As correctly asked, the exact code depends on the GUI toolkit and platform, but the pattern is the same: validate the number, pass it to the second form, create controls at runtime, and collect the values back into a data structure.

A minimal, framework-agnostic pattern (constructor receives the count; form builds controls in a loop and stores references):

Form2::Form2(int childCount, Widget* parent)
  : DialogBase(parent)
{
  layout = new VerticalLayout(this);
  for (int i = 0; i < childCount; ++i) {
    auto label = new Label("Child " + std::to_string(i+1), this);
    auto edit  = new TextBox(this);
    layout->addWidget(label);
    layout->addWidget(edit);
    edits.push_back(edit);
  }
}

void Form2::onSubmit()
{
  std::vector<std::string> names;
  for (auto e : edits) names.push_back(e->getText());
  // validate/save names into your model
}

Practical tips and pitfalls: use a layout manager (or a scrollable container) rather than hard coordinates so resizing works automatically; cap the accepted number (e.g., 50–100) to avoid creating hundreds of controls; remember ownership semantics (many toolkits delete child widgets when the parent is destroyed, raw Win32 requires manual cleanup); set sensible tab order and labels; validate/trim each name before saving. As indicated, separate the UI from the data model — store children in a vector or simple tree node structure so the UI only edits the model. An alternative UX is an editable list/Grid or an "Add child" button to append fields one at a time, which often scales and feels cleaner than pre-creating many empty boxes.

Recommended Answers

All 2 Replies

what compiler? what operating system? what GUI library?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.