Added Checkboxes Dynamically now I want change there state

D

Dan H

I have been able to add controls dyanmically to a windows application.
And I can get the Click event working beautifully. But now I want to
use an another event to change the state of the check box but I can
seem to figure out how to work with the control.

So in the code below I create a bunch of check boxes and I want the
event called IFK_InputChange (where I have an external hardware device
that I use as IFK, it works no problems) to update the chkInput check
boxes that I have created.

Any suggestions would be appreciated.



Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load

End Sub

Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
For i As Integer = 0 To IFK.GetNumInputs - 1
Dim chkInput As New CheckBox
chkInput.Location = New Drawing.Point(110, 170 + i * 20)
chkInput.TabIndex = i
chkInput.Tag = i.ToString
chkInput.Name = "input" + i.ToString
chkInput.Text = chkInput.Tag.ToString
AddHandler chkInput.Click, AddressOf ClickInputs
Controls.Add(chkInput)
Next

End Sub

Private Sub ClickInputs(ByVal sender As Object, ByVal e As
EventArgs)
MessageBox.Show("Clicked was " & DirectCast(sender,
CheckBox).Tag.ToString)
End Sub

Private Sub IFK_InputChange(ByVal sender As Object, ByVal e As _
InputChangeEventArgs) Handles IFK.InputChange
MessageBox.Show(e.getIndex & " is " & e.getState)
End Sub

End Class
 
A

Armin Zingler

Dan H said:
I have been able to add controls dyanmically to a windows
application. And I can get the Click event working beautifully. But
now I want to use an another event to change the state of the check
box but I can seem to figure out how to work with the control.

So in the code below I create a bunch of check boxes and I want the
event called IFK_InputChange (where I have an external hardware
device that I use as IFK, it works no problems) to update the
chkInput check boxes that I have created.

Any suggestions would be appreciated.



Public Class Form1


private f_checkboxes as checkbox()

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load

End Sub

Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.


redim f_checkboxes(IFK.GetNumInputs - 1)

For i As Integer = 0 To IFK.GetNumInputs - 1
Dim chkInput As New CheckBox
chkInput.Location = New Drawing.Point(110, 170 + i * 20)
chkInput.TabIndex = i
chkInput.Tag = i.ToString
chkInput.Name = "input" + i.ToString
chkInput.Text = chkInput.Tag.ToString
AddHandler chkInput.Click, AddressOf ClickInputs
Controls.Add(chkInput)


f_checkboxes(i) = chkInput

Next

End Sub

Private Sub ClickInputs(ByVal sender As Object, ByVal e As
EventArgs)
MessageBox.Show("Clicked was " & DirectCast(sender,
CheckBox).Tag.ToString)
End Sub

Private Sub IFK_InputChange(ByVal sender As Object, ByVal e As _
InputChangeEventArgs) Handles IFK.InputChange
MessageBox.Show(e.getIndex & " is " & e.getState)


f_checkboxes(e.getIndex).checked = ...

End Sub

End Class



Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top