none
Adding Fields Dynamically To A Form From A Database RRS feed

  • Question

  • Hi.

    I have an SQLITE database and I just want to add controls to a form dynamically based on fields of a table in my database file.

    I plan mapping the whole database to an XML file and embedding that XML file to my program in order to add controls to a form. Is that a good idea or not? (Making the program insecure maybe?)

    Thanks.

    • Edited by samialtas Thursday, June 27, 2019 7:32 AM
    Thursday, June 27, 2019 7:31 AM

Answers

  • Hello,

    On the surface the idea is sound yet the mechanics behind handling all that goes along with completing such a task there are many things to consider from validating data which would be wise to move validation from the form to concrete classes with data annotations, events to consider which there are many to consider, how to place controls on the form and consider when working with TextBox/Label combinations (best done with custom user controls) how to properly align them and the ordering of them e.g. First name followed by Last name etc.

    If you were to continue down this path information would be best retrieved from either a binary data file or from tables in a database.

    About the only place I've seen this work is a) in a multi-million dollar enterprise solution that stored all that was needed to setup forms with a template for positioning controls b) a web library (which of course would not work for you) which positioned controls via a JSON schema file.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by samialtas Friday, June 28, 2019 7:51 AM
    Thursday, June 27, 2019 10:17 AM
    Moderator

All replies

  • Hello,

    On the surface the idea is sound yet the mechanics behind handling all that goes along with completing such a task there are many things to consider from validating data which would be wise to move validation from the form to concrete classes with data annotations, events to consider which there are many to consider, how to place controls on the form and consider when working with TextBox/Label combinations (best done with custom user controls) how to properly align them and the ordering of them e.g. First name followed by Last name etc.

    If you were to continue down this path information would be best retrieved from either a binary data file or from tables in a database.

    About the only place I've seen this work is a) in a multi-million dollar enterprise solution that stored all that was needed to setup forms with a template for positioning controls b) a web library (which of course would not work for you) which positioned controls via a JSON schema file.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by samialtas Friday, June 28, 2019 7:51 AM
    Thursday, June 27, 2019 10:17 AM
    Moderator
  • I'll consider custom controls while coding. 

    Thanks for the great advice.

    Friday, June 28, 2019 7:51 AM
  • IMO, sure you can do it if you're developing a Windows desktop solution that is using WPF and XAML. There are plenty of articles on the subject you can find using Bing or google.

    https://www.codeproject.com/Tips/356234/Dynamically-Generating-Forms-in-WPF-and-Silverligh

    You'll probably find developes in the WPF forum that have done  something similar.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf

    Friday, June 28, 2019 3:15 PM