Using C# 2.0 what is the best way to implement dynamic form controls?
I need to provide a set of controls per data object, so should i just do it manually and lay them out while increment the top value or is there a better way?
Dynamic forms are composite forms that allow you to present varying amounts of data to users. These forms change their layout according to the data they receive from the prefilling services at the time of rendering, so each separate request for form generation produces a form with a different length or content.
What are Salesforce Dynamic Forms? The premise of Dynamic Forms is to create user centric, intuitive page layouts that display the right information at the right time. Over time, the page layout, or “Details” section in Lightning pages, can become congested with fields.
A dynamic form requires an object model that can describe all scenarios needed by the form functionality. The example hero-application form is a set of questions —that is, each control in the form must ask a question and accept an answer. The data model for this type of form must represent a question.
Unlike the traditional page layout where you can only add a field once, you can add a field multiple times using Dynamic Forms. The reason for this is because you may create multiple Field Sections that display fields based on different criteria or for different record types or users.
You can use panels with automatic layout such as FlowLayoutPanel and TableLayoutPanel.
Unfortunately there are only 2 panels with automatic layout out of box but you can create custom layout panel.
I would recommend you to read following articles:
How to: Create a Resizable Windows Form for Data Entry
Walkthrough: Creating a Resizable Windows Form for Data Entry
Another option would be using of WPF (Windows Presentation Presentation).
WPF is a perfect match for your task.
WPF controls can be hosted in WinForms apps so you don't have to switch to it completely.
@Sam I know this question was about Windows Forms, but you should definitely start looking at WPF. This sort of scenario is really easy in WPF with DataTemplates and TemplateSelectors.
What do you mean by “dynamic”? A new, fixed set of controls for each data row in the data set? Then use a UserControl
that contains your controls.
Or do you mean that, depending on your data layout, you want to provide the user with a customized set of controls, say, one TextBox
for each column?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With