Hi,
I am working on an assignment where i need to create controls dynamically in a Form and when i click "execute button" in the form it should generate a query based on the dynamic controls selection.
Each dynamic control reflect one database column.
The control's can be combo,textbox etc. The execute button is not a dynamic button.
Could you please suggest me a good approach to solve the problem..

Thanks
Subha

If you are using Visual Studio, you could drag a TextBow in a Forms application. See in the generated files how VS does it and act accordingly.

The problem there is i have around 100 controls(columns) and out of that i need only 20 controls to be created dynamically based on some settings. Creating 100 controls where in i need only 20 controls, this may consume much memory space. Please suggest me..

Do I understand you well, do you want to have some sort of "excel-like" sheet wich fetches data from a database after pushing an execute button? Please explain a bit more.

Yes correct.. i am planning to do the same. when i select the columns and when executed it will give me the results.

Use a DataGridView object for that. Example
A DataGridView is rather "heavy" in the beginning to get a grasp on(I was for me!) But in the end it pays off. Success!

You are correct but i needed to use only dynamic controls because of Look and feel.

In the example given the DatgridView is constructed dynamically. Or are you only allowed to use TextBoxes and ComboBoxes?

UI design doesnt allow me to Datagridview. The search would consists of TextBox,Combox box,checked list box,checkbox,datetimectrl etc. The problem i am facing is how should i access the controls througt the file after creating the controls dynamically.

You could dynamically create an array of TextBox objects.
It is for example often done to create a sudoku puzzle etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.