|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Changing the checked state of Dynamically added checkboxesAnd 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 Dan,
You mean something as beneath typed in this message so watch typos. \\\ Public sub SetCheckBox(byval chkstate as Boolean, byval checkboxindex as integer) For each ctr as Control in me.controls if Typeof ctr Is CheckBox then dim chk as checkbox = ctr if chk.name = "input" & checkboxindex.tostring then chk.checked = chkstate end if end if end for /// (You can as well create an arraylist of refrences to the textboxes you use global in your program) I hope this helps, Cor Show quoteHide quote "Dan H" <dan.he***@gmail.com> schreef in bericht news:1141946299.117127.185460@i39g2000cwa.googlegroups.com... >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 >
Can't modify instance of a class from within the class!
creating independant application vb 2005 express edition Fastest way to load jpg images ? Access digital camera How to.... Question..... Can you insert elements into an XML file that exists as a string? MIDI guitar sheet music player in .net Refresh my memory on datatables, datasets etc. Enum and FlagsAttribute System.Drawing exception |
|||||||||||||||||||||||