Hi i want to add more text field when pressing a button.
because i making a form which belongs to "Saling products" but obvouseley any customer can purchase one product and also can purchase many products so how is it possible to put more fields when click button add fields..
or any one have good way to make "Salling product" form?
Regards...
Farhad Idrees

Recommended Answers

All 7 Replies

Obviously you want something like a "shopping basket" or am I wrong?
Look at how differt "shopping" sites handle this and try to implement it that way.
Happy programming :)

Hi,

the way i would do it is that i would use either a separate control for the name, qty, price and total price, and every time the button is clicked a new control would be added to the form; at the end you just count the number of controls and do the sum.

also, i am not sure if you can use it, but it is probably easy to do in a datagridview, which will simplify everything.

Regards

Use TableLayoutPanel control.

private void Form1_Load(object sender, EventArgs e)
        {
            TableLayoutPanel tp = new TableLayoutPanel();
            tp.AutoScroll = true;
            tp.ColumnCount  = 2;
            tp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            
            TextBox tx1 = new TextBox();
            TextBox tx2 = new TextBox();

            Button bt1 = new Button() { Text = "Add" };
            bt1.Location = new Point(100, 120);
            bt1.Click += (sa, ea) =>
                {
                    tp.RowCount++;
                   
                    TextBox tx11 = new TextBox();
                    TextBox tx22 = new TextBox();
                    tp.Controls.Add(tx11, 0, 0);
                    tp.Controls.Add(tx22, 1, 0);

                };
            tp.Controls.Add(tx1, 0, 0);
            tp.Controls.Add(tx2,  1, 0);
         

            Controls.Add(tp);
            Controls.Add(bt1);
            
        }

Hi,

the way i would do it is that i would use either a separate control for the name, qty, price and total price, and every time the button is clicked a new control would be added to the form; at the end you just count the number of controls and do the sum.

also, i am not sure if you can use it, but it is probably easy to do in a datagridview, which will simplify everything.

Regards

@ Williamrojas
ya exactly i want to do this as u mentioned but i m new i c#..
kindly provide me code how is it possible?i tried but i couldn't do this :(
i hope u wil..
Regards..
Farhad

Use TableLayoutPanel control.

private void Form1_Load(object sender, EventArgs e)
        {
            TableLayoutPanel tp = new TableLayoutPanel();
            tp.AutoScroll = true;
            tp.ColumnCount  = 2;
            tp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            
            TextBox tx1 = new TextBox();
            TextBox tx2 = new TextBox();

            Button bt1 = new Button() { Text = "Add" };
            bt1.Location = new Point(100, 120);
            bt1.Click += (sa, ea) =>
                {
                    tp.RowCount++;
                   
                    TextBox tx11 = new TextBox();
                    TextBox tx22 = new TextBox();
                    tp.Controls.Add(tx11, 0, 0);
                    tp.Controls.Add(tx22, 1, 0);

                };
            tp.Controls.Add(tx1, 0, 0);
            tp.Controls.Add(tx2,  1, 0);
         

            Controls.Add(tp);
            Controls.Add(bt1);
            
        }

@Adatapost
:)
it works for me i m working on it if i would have problem so i'll tell u again..
thanks buddy :)

Use TableLayoutPanel control.

private void Form1_Load(object sender, EventArgs e)
        {
            TableLayoutPanel tp = new TableLayoutPanel();
            tp.AutoScroll = true;
            tp.ColumnCount  = 2;
            tp.RowStyles.Add(new RowStyle(SizeType.AutoSize));
            
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            tp.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize ));
            
            TextBox tx1 = new TextBox();
            TextBox tx2 = new TextBox();

            Button bt1 = new Button() { Text = "Add" };
            bt1.Location = new Point(100, 120);
            bt1.Click += (sa, ea) =>
                {
                    tp.RowCount++;
                   
                    TextBox tx11 = new TextBox();
                    TextBox tx22 = new TextBox();
                    tp.Controls.Add(tx11, 0, 0);
                    tp.Controls.Add(tx22, 1, 0);

                };
            tp.Controls.Add(tx1, 0, 0);
            tp.Controls.Add(tx2,  1, 0);
         

            Controls.Add(tp);
            Controls.Add(bt1);
            
        }

i tried so much but...
i m not able to make setting in my form because i m beginner of c#..
i provide u my code of sale form i hope u can do..
whenever i click button "add fields" so new combobox,quantity field, price field,totalprice field show below the above fields..
but it must be continuos proccess because any customers can purchase one product and any one can purchase 10 products so that way i will need to press button 10times.

I Think its better to add the columns when initializing the datagrid so that whatever the columns u want? U can make it enabled and disabled as all the products that are known to u before only

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.