Dynamically creating a user interface in C #

I am developing a library application. Not a library of a large size, but a library of a very small scale, where my main task is simply to store information about books. But this library application should be able to adapt to any professional private library. For example, for a lawyer, in addition to basic information about the book (title, author, publisher, etc.), there may be other special fields associated with the book (case number, court number, etc.). The doctor may have other special attributes for the book. The same goes for other professions.

So, I am going to use the SQL Server CE database, and I hope to have a BOOK table with the usual attributes and at the request of ALTER, so that the table meets the special needs (add more columns).

But my concern is with the dynamic dynamic interface to support new attributes.

Are there any approaches to solving the dynamic generation of a graphical interface?

I am not asking for the full code (which I obviously won’t get), but if you have any encoding to support the approach, please be kind enough to post it :)

Is there anything I need to know about the pros, cons, dead ends, warnings or warnings?

+7
user-interface c # dynamic sql-server-ce
source share
4 answers

On the data model side that @devnull chose, you describe the implementation of custom fields, and @devnull describes the model. What are the design patterns for supporting custom fields in an application?

The choice of the data model and the creation of the user interface are closely related, so you cannot really answer the question of creating the user interface until you decide the model of your data model / user field template. My initial reaction was the same as @devnull on an alternative approach, but there really is no great solution.

You can reduce complexity if you have a superset of all possible fields and allow the user to enable / disable those that match their application domain. I made several implementations of custom fields in an application with very smart people, and it is always difficult. If you understand the application area well enough, you can stay away from flexible architectures and save a lot of grief.

Note that the important question is whether they need to request custom fields. This is much easier if you do not need to support a common request. You just use userdate1, usern, etc. And provide a metadata table for labels.

+5
source share

I don't know if modifying a table is a dynamically good solution. Instead, you can have a lookup table in which you can define data types, and a book details table in which you will store this data. Then you can display this data in the book editing section as a data file that has data types as rows, with each row having a column in which you are editing the value. Of course, the detail of the book may be something other than a simple string value, but this can be dealt with with ease. Hope I was clear enough :)

------------- ----------------- ---------------- | Books | | BooksDetail | | DetailTypes | ------------- ----------------- ---------------- | ID (PK) | 1 n | ID (PK) | 1 1 | ID (PK) | | AuthorID | --------> | BookID | -------> | Name | | Title | | DetailID | | Description | | Year | | Value | ---------------- ------------- ----------------- 
+4
source share

There are many code generation tools. Some of them generate code with an easy to use graphical interface.

Mygenation

CodeNGen

Codesmith

IgnyteDataLayerGen

NetGenerationCodeGen

OxyGen Code Generator

. Nettiers

CodeThatBuilder

CslaGenerator

CodeBreeze

Alternatively, the following codes may make your life easier.

You may have a common base form for these objects:

 public partial class BaseForm : Form { ///////////Event Mechanism/////////// protected internal event ItemStateChanged ItemStateChangeEvent; protected internal void OnItemStateChanged() { if (ItemStateChangeEvent != null) { ItemStateChangeEvent(); } } ///////////Event Mechanism/////////// protected internal Label ErrorMessageTextBox { get { return this.errorMessageTextBox; } set { this.errorMessageTextBox = value; } } protected internal ToolStripStatusLabel TotalToolStripStatusLabel { get { return this.totalToolStripStatusLabel; } set { this.totalToolStripStatusLabel = value; } } protected internal FormViewMode FormViewMode { get; set; } public BaseForm() { InitializeComponent(); } } 

And the general base form for collections:

 public partial class CollectionBaseForm : BaseForm { protected internal ToolStripMenuItem ReportMenu { get { return this.reportsToolStripMenuItem; } set { this.reportsToolStripMenuItem = value; } } protected internal DataGridView DataGridView { get {return this.dataGridView1 ;} set {dataGridView1 = value ;} } protected internal Button SearchButton { get { return btnSearch; } set { btnSearch = value; } } protected internal Button AddNewButton { get { return btnAddNew; } set { btnAddNew = value; } } protected internal Button EditButton { get { return btnEdit; } set { btnEdit = value; } } protected internal Button DeleteButton { get { return btnDelete; } set { btnDelete = value; } } protected internal Button PickButton { get { return btnPick; } set { btnPick = value; } } private FormViewMode _formViewMode; public FormViewMode FormViewMode { get { return _formViewMode; } set { _formViewMode = value; EnableDisableAppropriateButtons(_formViewMode); } } private void EnableDisableAppropriateButtons(FormViewMode FormViewMode) { if (FormViewMode == FormViewMode.Collection) { AddNewButton.Enabled = true; EditButton.Enabled = true; DeleteButton.Enabled = true; PickButton.Enabled = false; } else if (FormViewMode == FormViewMode.Picker) { AddNewButton.Enabled = false; EditButton.Enabled = false; DeleteButton.Enabled = false; PickButton.Enabled = true; } } public CollectionBaseForm() { InitializeComponent(); this.MaximumSize = this.MinimumSize = this.Size; this.FormViewMode = FormViewMode.Collection; } private void closeToolStripMenuItem_Click(object sender, EventArgs e) { this.Close(); } protected override void OnResize(EventArgs e) { base.OnResize(e); } } 

Then all your forms will have the same general appearance:

alt text

+3
source share
+1
source share

All Articles