473,388 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Changing the checked state of Dynamically added checkboxes

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

Mar 9 '06 #1
1 2711
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
"Dan H" <da*******@gmail.com> schreef in bericht
news:11**********************@i39g2000cwa.googlegr oups.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

Mar 10 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RodBillett | last post by:
I have a situation where I have 3 checkboxes - and at least 1 needs to be selected at all times... I have implemented the code that allows this behavior to happen, BUT Viewstate gets all messed...
7
by: DJ Dev | last post by:
Hi All, I have a complex problem. I have dropdownlists (usually 3-5) and the user selects some value from these and for each value selected, datagrids are shown to the user. I am creating the...
0
by: Scott P. | last post by:
I'm creating an app using ASP .NET (my second app so bear with me here) that basically builds a PDF file based on a bunch of user selections. I have a page which displays a series of checkboxs...
4
by: Alexander Mueller | last post by:
Hi all, in a CheckedListBox there are afaics two members that change the checked-flag for an item i.e. SetItemChecked and SetItemCheckState. In the online-help there is a remark that...
2
by: Pete Moss | last post by:
During a postback event, I am having trouble retrieving the state of a CheckBox Control that I am dynamically adding to a DataGrid Control using ASP.NET 1.1. I have no trouble adding the...
1
by: Kevin R | last post by:
This is one of the weirdest problems I have ever run into. I have had to trim down a bunch of code to give a sample that is more easily readable by those who will view this. Here is the problem:...
0
by: cyberdawg999 | last post by:
Greetings all in ASP land I have overcome one obstacle that took me 2 weeks to overcome and I did it!!!!! I am so elated!! thank you to all who invested their time and energy towards helping me...
0
by: J | last post by:
I'm dynamically adding checkboxes in the Page_Load (regardless of PostBack). When IsPostBack, the checkboxes display as I expected and their checked/unchecked status is also as expected. At this...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.