Hi.. I created a custom control made up of several text boxes and other controls to be used in a recipe program (the control stores ingredient info).
Since I don't know how many ingredients a recipe needs, I give the user the option to enter the number of ingredients they need and I then add in additional custom controls as needed using:
This works fine.. works great actually.. what I'm trying to figure out now is..
If I suddenly need to remove one of these controls -OR- they cancel the entry and I need to revert the form back to its original setting with only 1 control, how do I remove the excess?
I tried things like
Or even doing the remove with the name in a string (since the names are dynamically generated I can't refer to them specifically during program time).
Any suggestions on how I can do this? And although i know I could prob clear out the entire form and create the form from scratch during runtime, I'm trying to avoid that.
-Ko
Since I don't know how many ingredients a recipe needs, I give the user the option to enter the number of ingredients they need and I then add in additional custom controls as needed using:
VB.NET:
[SIZE=2][COLOR=#0000ff]
Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] CreateRecipeInstructionFields([/SIZE][SIZE=2][COLOR=#0000ff]ByRef[/COLOR][/SIZE][SIZE=2] iFields)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] iCount [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ctrlRecInstructEntry [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] RecipeInstructionEntry
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ToolStripProgressBar1.Value = iFields - 1
[/SIZE][SIZE=2][COLOR=#0000ff]Do[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] iCount < iFields
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ToolStripProgressBar1.Increment(1)
ctrlRecInstructEntry = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] RecipeInstructionEntry
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].grpRecInstuctLst.Controls.Add(ctrlRecInstructEntry)
ctrlRecInstructEntry.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]False
[/COLOR][/SIZE][SIZE=2]ctrlRecInstructEntry.Name = [/SIZE][SIZE=2][COLOR=#800000]"RecipeInstructionEntry"[/COLOR][/SIZE][SIZE=2] & iTotalRecInstructCtrls
ctrlRecInstructEntry.lblRecipeEntry.Text = iTotalRecInstructCtrls + 1 & [/SIZE][SIZE=2][COLOR=#800000]")"
[/COLOR][/SIZE][SIZE=2]ctrlRecInstructEntry.Location = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Point(RecipeInstruction_XLoc, (YRecInstructSize + YCtrlSpace) + iLastRecInstructCtrlCreated_YLoc)
iLastRecInstructCtrlCreated_YLoc = (YRecInstructSize + YCtrlSpace) + iLastRecInstructCtrlCreated_YLoc
ctrlRecInstructEntry.BringToFront()
ctrlRecInstructEntry.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True
[/COLOR][/SIZE][SIZE=2]iTotalRecInstructCtrls += 1
iCount += 1
ctrlRecInstructEntry = [/SIZE][SIZE=2][COLOR=#0000ff]Nothing
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Loop
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].ToolStripProgressBar1.Value = 0
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]
This works fine.. works great actually.. what I'm trying to figure out now is..
If I suddenly need to remove one of these controls -OR- they cancel the entry and I need to revert the form back to its original setting with only 1 control, how do I remove the excess?
I tried things like
VB.NET:
[SIZE=2]
ctrlRecInstructEntry = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] RecipeInstructionEntry
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].grpRecInstuctLst.Controls.Remove(ctrlRecInstructEntry)
[/SIZE]
Or even doing the remove with the name in a string (since the names are dynamically generated I can't refer to them specifically during program time).
Any suggestions on how I can do this? And although i know I could prob clear out the entire form and create the form from scratch during runtime, I'm trying to avoid that.
-Ko