Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best method to build data entry forms in WPF?

When building WPF forms that are used for data entry (e.g. A bunch of labels next to a bunch of textboxes and comboboxes) I've seen two methods:

  • Create a master Grid, divide it into two columns, and add rows with Height="auto" for each field and two rows for header and footer (and submit button), and each label and text box has their own row.
  • The other method is to create a master stackpanel and inside it a horizontal stackpanel for each pair of label-textbox.

How do you design your data entry forms? I'm currently torn between the two methods, maybe there's an alternative that I'm unaware of?

EDIT: Henk said I should define best and I think I agree, by best I mean easiest to maintain, create, align and add or remove fields from as demands change.

So far the only criteria by which the grid is better is ease of alignment.

like image 521
Ziv Avatar asked Apr 11 '11 19:04

Ziv


2 Answers

definately first method!

it's well aligned, especially with the use of SharedSizeGroup so you can have the same alignment eg in different Groupboxes.

like image 167
Markus Hütter Avatar answered Nov 15 '22 23:11

Markus Hütter


I have used both and it really depends upon how your form is going to look. If you have a really simple layout where you are going to have labels and and corresponding fields of approximately the same size then your first method works well. It lets you create two columns that line up very well. However, if your fields are of varying withs, and heights and you want to be more complex with the layouts then a hybrid approach may be best. If you are doing anything more complex than just labeling fields on basic controls you may want to create user controls rather than just using what is there out of the box. When laying out fields in both a horizontal and vertical jagged manner it becomes hard to maintain the grid layout as you have to wind up having a grid with lots of columns and rows. The fields and labels have to span columns and rows to get your alignment correct. This works, but is a nightmare if you ever want to reorganize the form.

For what you wrote, it sounds like the first approach is best. If its simple now and some point in the future it becomes more complex, its easy to change. However, if you have a more complex layout already then a pure grid based approach probably isn't best.

like image 32
Craig Suchanec Avatar answered Nov 16 '22 01:11

Craig Suchanec