views:

38

answers:

2

i am working on a Windows Forms application using VB.net. It basically is an application made in vb 6.0 being upgraded to vb.net. Now i have an idea but i am not sure if it exists.

Say i have a database (My_DB) and it has a table (item_details).

I wish to make dataentry into the elements of item_details table which currently has 6 fields. So i add 6 textboxes and 6 labels and make user enter them, one record at a time.

Say tomorrow i add or remove a field from the table item_details. I want such a mechanism where if the underlying table structure changes, the corresponding number of textboxes and labels must automatically change themselves. i.e. if i remove a column and now i have 5 columns, the form must also have 5 labels and 5 textboxes. Are there any controls to achieve this functionality. Am i talking MVC here? Help needed thanks.

+1  A: 

Yes, you can do that with dynamic control creation. Every time it is time to draw those textboxes, you check the database, and then draw accordingly. I'm sure that ADO.NET has capability to inspect number of columns in table.

Knowing this, your biggest problem is positioning of those textboxes. Best controls for positioning dynamic content are FlowLayoutPanel & TableLayoutPanel. Check them out on the Net...

Btw, when you are talking patterns, best way to do this would be to use Mediator pattern, and encapsulate this whole logic in some custom user-control or something.

Sapphire
Thanks for the information. I will look into the mediator pattern. I think there is some control too like we have bindingnavigation control to populate controls.
Anirudh Goel
A: 

Personally I would be opposed to doing this. If you are adding columns to the table you need to physically look at the queries and forms to see whether they need adjustment. And sometimes you might want the new column in a differnt position or to attch it to a lookup table. Sometimes when you add a column it needs to be onthe form and sometimes you might add a column for intenal use only that you don't want users to see. Plus, your query should not be returning the all the columns unless you specify them. You aren't using select * in a production environment are you? This is an extremely poor practice as it wastes network and server resources. And finally, if you think you wll be freqeently adding columns to this table, then you need to redesign now. Table structure should be relatively stable.

HLGEM