My GUI page has 3 buttons
1.AddButton //On clicking it creates textbox and checkbox (beside textbox).
2.RemoveButton //It deletes the textboxes(and the data) for which the checkboxes are checked
3.Updatebuton //It updates total no. of textboxes(its data) in the database.
//Code for dynamic creation of textbox and checkbox when Addbutton is clicked.
public int position = 30;
private void btnAdd_Click(object sender, EventArgs e)
{
TextBox newtxtbox = new TextBox();
CheckBox newchkbox = new CheckBox();
newchkbox.Location = new System.Drawing.Point(230, 72 + position);
newtxtbox .Location = new System.Drawing.Point(27, 72 + position);
newtxtbox .Size = new System.Drawing.Size(187, 20);
this.btnAdd.Location = new System.Drawing.Point(27, 109 + position);
this.btnRem.Location = new System.Drawing.Point(113, 109 + position);
groupBox1.Controls.Add(newtxtbox);
groupBox1.Controls.Add(newchkbox);
position+= 30;
}
How Could I write a code which deletes the textboxes for which checkboxes are clicked because all are dynamically created.
And finally how to update in the database getting the total number of textboxes and its data.
Also I am using windows.Forms which doesnt allow to use Id related to each textbox or checkbox.
handle dynamic insertion and deletion of textboxes depending upon the checkboxes chec
Started by @kriti, May 31 2010 12:30 AM
1 reply to this topic
#1
Posted 31 May 2010 - 12:30 AM
|
|
|
#2
Posted 31 May 2010 - 01:08 AM
Use a TextBox and Checkbox array, then loop through it and see if the checkBox is checked.
struct Boxes {
TextBox tb1;
CheckBox cb1;
}
Boxes[] myArray = new Boxes[10];
this.Controls.Add(myArray[1].TextBox);
//etc...
Are you a newbie programmer trying to learn C#? Check out my small tutorial: Visual C# Programming Basics


Sign In
Create Account

Back to top









