When i click on the button then control has add autometically at the TableLayoutPanel

Solution
[ 1 ]
  First you have to declare 2 variables globally. Like ,

int ypos=35;
int rowindex=1;

[ 2 ]   Then we have to take one button in windows form. Then write this code to its click Event.

private void btnNewItm_Click(object sender, EventArgs e)
{

createitems(ypos,rowindex);

ypos++;

rowindex++;

}

[ 3 ]  Write this function , in this function we will take two combobox and two TextBoxes.

public void createitems(int t1, int rowpnl)
{
tb1 = new TextBox();
tb1.Name = “tb1″;
tb1.Location = new Point(17, t1);
tb1.Width = 84;
tb1.Height = 25;
tb1.Text = “1″;
tlp.Controls.Add(tb1, 0, rowpnl);
//tlp.Controls.Add(tb1);

cmbitem = new ComboBox();
cmbitem.Name = “cmbitem”;
cmbitem.Width = 101;
cmbitem.Height = 25;
cmbitem.Location = new Point(112, t1);
cmbitem.DropDownStyle = ComboBoxStyle.DropDownList;

BAL.BLInvProduct objdcate = new BAL.BLInvProduct();
cmbitem.DataSource = objdcate.BindType();
cmbitem.DisplayMember = “nProdName”;
cmbitem.ValueMember = “nProdName”;

//pnlText.Controls.Add(cmbitem);
tlp.Controls.Add(cmbitem, 1, rowpnl);
cmbitem.SelectedIndexChanged += new EventHandler(cmbitem_SelectedIndexChanged);

cmbTax = new ComboBox();
cmbTax.Name = “cmbTax”;
cmbTax.Width = 108;
cmbTax.Height = 25;
cmbTax.Location = new Point(220, t1);
cmbTax.DropDownStyle = ComboBoxStyle.DropDownList;

BAL.BLTax objtax = new BAL.BLTax();

cmbTax.DataSource = objtax.BindTax();
cmbTax.DisplayMember = “nTaxName”;
cmbTax.ValueMember = “nTaxName”;
tlp.Controls.Add(cmbTax, 2, rowpnl);
//pnlText.Controls.Add(cmbTax);

tb2 = new TextBox();
tb2.Name = “tb2″;
tb2.Location = new Point(334, t1);
tb2.Width = 110;
tb2.Height = 25;
//pnlText.Controls.Add(tb2);
tlp.Controls.Add(tb2, 3, rowpnl);
}

[ 4 ] Then You can run this code.

 

 

 

 

About the Author

avatar