Adding an event to a dynamically created textbox - Windows forms app

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
OK, so my project is like this:
The user selects a folder from their computer that holds a list of subfolders. The program then dynamically inserts a check boxes per subfolder within a seperate cell of a Table Layout Panel.
I want to and a simple Click event to each checkbox control so that when a control is clicked, it counts all of the check boxes on the form that are checked.
How do I go about adding the event handler to the checkboxes when they are created. Here is the code that adds the checkboxes:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; Dim iCol <span style="color:Blue; As <span style="color:Blue; Integer = 1
<span style="color:Blue; Dim objFolder <span style="color:Blue; As <span style="color:Blue; Object = <span style="color:Blue; Nothing

<span style="color:Blue; For j = 0 <span style="color:Blue; To rCount - 1 <span style="color:Green; 0 to dynamic number of rows
<span style="color:Blue; For k = 0 <span style="color:Blue; To 3 <span style="color:Green; 4 columns in the TableLayoutPanel

<span style="color:Blue; If iCol <= fCol.<span style="color:Blue; Count <span style="color:Blue; Then <span style="color:Green; fcol is the collection of subfolders

<span style="color:Blue; Dim dChk <span style="color:Blue; As <span style="color:Blue; New CheckBox
objFolder = fCol.Item(iCol)

dChk.Name = <span style="color:Blue; CStr(k) & <span style="color:#A31515; "," & <span style="color:Blue; CStr(j) <span style="color:Green; create the name of the CheckBox e.g. called "0,0" in the first cell
dChk.Text = objFolder.FolderTitle <span style="color:Green; set the text to the name of the subfolder

<span style="color:Blue; Dim IDpos <span style="color:Blue; As <span style="color:Blue; New TableLayoutPanelCellPosition(k, j)
TableLayoutPnl.SetCellPosition(dChk, IDpos) <span style="color:Green; set the position in the table Layout Panel
TableLayoutPnl.Controls.Add(dChk) <span style="color:Green; Add the control in the cell
dChk.AutoSize = <span style="color:Blue; True

iCol += 1
<span style="color:Blue; End <span style="color:Blue; If
<span style="color:Blue; Next
<span style="color:Blue; Next
[/code]
<br/>
<br/>
<hr class="sig You cant dangle the bogus carrot of possible reconciliation in front of me whilst riding some other donkey

View the full article
 
Back
Top