Form Building

Data-Driven Forms: FillInFrom and CallAfterFillIn

A GPAL form isn't limited to one screen of static controls. FillInFrom can drive the same form through every row of a grid, file, or database query, with CallAfterFillIn running your logic between rows.

Filling a Form from Data

FillInFrom(source) sets the value of every input control on the form from a corresponding column in the source -- a GPALFile, a GPALDatabase, or an IGPALGrid<string>. AppendFrom adds to each control's current value instead of replacing it, and InsertFrom places new data at the beginning of the current value -- both useful for building up a value across multiple passes rather than starting over each time. Because ShowDialog blocks and ends the fluent chain, FillInFrom (and AppendFrom/InsertFrom) must come after Show(), which displays the form without blocking, and before the final ShowDialog.

GPAL.Form

.WithTitle("Review Record")

.WithFormControl((Input)GPAL.Input.WithName("Name"))

.WithFormControl((Input)GPAL.Input.WithName("Email"))

.Show()

.FillInFrom("contacts.csv")

.ShowDialog();

One Form, Many Rows

CallAfterFillIn registers a delegate that runs once per row, right after that row's data has been applied to the form's controls. It receives the form itself, the source grid, and the row index. Returning anything other than CallIfStatus.Terminate continues to the next row; CallIfStatus.Terminate stops the loop. Register CallAfterFillIn before Show() and FillInFrom, since FillInFrom triggers the per-row callback.

GPAL.Form

.WithTitle("Approve Record")

.WithFormControl((Input)GPAL.Input.WithName("Name"))

.WithFormControl((Input)GPAL.Input.WithName("Total"))

.CallAfterFillIn((form, grid, rowIndex) =>

{

// Inspect or let the user edit this row's controls, then continue

return CallIfStatus.NotHandled;

})

.Show()

.FillInFrom(pendingOrdersGrid)

.ShowDialog();

TIP

There's no 'handled vs not handled' distinction here like CallIfFound/CallIfNotFound. Any value other than CallIfStatus.Terminate just continues. CallIfStatus.Terminate logs an INFO event and throws, so wrap FillInFrom in a try/catch to use it deliberately.

Reading Values Back

After the user interacts with a form -- editing an input, checking a box, picking from a combo box -- those values live on the control objects themselves (GPALInput.Text, GPALCheckbox.IsChecked, and so on, the same properties WithText/WithChecked set going in), readable any time after ShowDialog returns. For realtime updates instead of waiting on the dialog, WithCallback wires a handler straight to a control's default event, or to any other ControlEventType via ForEvent.

var nameInput = GPAL.Input.WithName("Name").ToGPALObject();

var agreeCheckbox = GPAL.Checkbox.WithText("Confirmed").ToGPALObject();

GPAL.Form

.WithTitle("New Record")

.WithFormControl(nameInput)

.WithFormControl(agreeCheckbox)

.WithFormControl((Button)GPAL.Button.WithText("OK"))

.ShowDialog();

// After the dialog closes, read the values back

string enteredName = nameInput.Text;

bool wasConfirmed = agreeCheckbox.IsChecked;