473,386 Members | 1,773 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,386 software developers and data experts.

General Control(s) question

HI,

I have a user control where checkboxes are added to it dynamically from the
database. I want to be able "tell" the parent form what has been checked
and what hasn't. I know I have to iterate through the controls on the form,
check to see if the control's name has part of a substring to determine if
it is one of the controls i'm looking for and then cast it to the checkbox
type and return what i need. The ONLY issue i have is I'm not sure how to
do all that. I know what i need to do, just not sure how to do it.

i have the following as my starting point, but not sure where to go from
here. Can someone please help me w/ a quick example. Thanks in
advance.....

foreach(Control ctrl in this.Controls)
{
.....

}
Doug
Nov 16 '05 #1
2 1100
foreach(Control ctrl in this.Controls)
{
if (ctrl.Name.IndexOf("your-substring")>=0)
{
CheckBox chk = (CheckBox)ctrl;
if (chk.Checked)
... // perform your action here, you have chk.Name and chk.
}
}

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"Doug" <dk*******@hotmail.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
HI,

I have a user control where checkboxes are added to it dynamically from the database. I want to be able "tell" the parent form what has been checked
and what hasn't. I know I have to iterate through the controls on the form, check to see if the control's name has part of a substring to determine if
it is one of the controls i'm looking for and then cast it to the checkbox
type and return what i need. The ONLY issue i have is I'm not sure how to
do all that. I know what i need to do, just not sure how to do it.

i have the following as my starting point, but not sure where to go from
here. Can someone please help me w/ a quick example. Thanks in
advance.....

foreach(Control ctrl in this.Controls)
{
if (ctrl.Name.IndexOf("your-substring")>=0)
}
Doug

Nov 16 '05 #2
If the only reason you're checking the name is to be sure that the item is a
checkbox then you don't need to bother. You could use the "is" operator to
find out.

foreach (Control ctl in this.Controls)
{
if (ctl is CheckBox)
{
CheckBox chk = (CheckBox)ctl;
}
}

Another option would be to hook the event for the checkbox and then just let
it tell you its state instead of you having to go look for it:

private void SomeMethod ()
{
CheckBox chk = new CheckBox();
this.Controls.Add (chk);
chk.CheckedChanged += new EventHandler (chk_CheckedChanged);
}
private void chk_CheckedChanged(object sender, EventArgs e)

{

CheckBox chk = (CheckBox)sender;

if (chk.Checked)

//do something...

}

"John Wood" <j@ro.com> wrote in message
news:e$**************@TK2MSFTNGP11.phx.gbl...
foreach(Control ctrl in this.Controls)
{
if (ctrl.Name.IndexOf("your-substring")>=0)
{
CheckBox chk = (CheckBox)ctrl;
if (chk.Checked)
... // perform your action here, you have chk.Name and chk.
}
}

--
John Wood
EMail: first name, dot, last name, at priorganize.com
"Doug" <dk*******@hotmail.com> wrote in message
news:Oh**************@tk2msftngp13.phx.gbl...
HI,

I have a user control where checkboxes are added to it dynamically from

the
database. I want to be able "tell" the parent form what has been checked
and what hasn't. I know I have to iterate through the controls on the

form,
check to see if the control's name has part of a substring to determine
if
it is one of the controls i'm looking for and then cast it to the
checkbox
type and return what i need. The ONLY issue i have is I'm not sure how
to
do all that. I know what i need to do, just not sure how to do it.

i have the following as my starting point, but not sure where to go from
here. Can someone please help me w/ a quick example. Thanks in
advance.....

foreach(Control ctrl in this.Controls)
{
if (ctrl.Name.IndexOf("your-substring")>=0)


}
Doug


Nov 16 '05 #3

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

Similar topics

1
by: Andrew MacLean | last post by:
Hello all, I am fairly new to .NET, but not to VB. I have a couple of questions. 1. Shared Code Base I have a solution with several different applications within it. Many of the...
2
by: David | last post by:
I am running into situtations where confining all forms to just one window (instance of broswer) is becoming overly restrictive. Does ASP.NET provide ways to have multiple windows to interact with...
1
by: Dalan | last post by:
Before distributing a database that I have developed, I thought that I would ask the resident gurus a general question regarding Common Dialogs Control. Correct me if I'm wrong, but I have read...
8
by: Smkmdb1 | last post by:
Hi everyone, I'm a student of ASP.net. Being an ex Perl/CGI programmer who made extra cash making scripts and selling them on the web, I was wondering if one typically uses this format with...
6
by: David | last post by:
I am running into situtations where confining all forms to just one window (instance of broswer) is becoming overly restrictive. Does ASP.NET provide ways to have multiple windows to interact with...
3
by: JezB | last post by:
What's the generally accepted approach for using Styles and Stylesheets in a web application based on .aspx files, Web Controls, User Controls, and code-behind modules (c# in my case)? Most style...
1
by: Baldy | last post by:
Hi All, Just a bit of a general question. I've heard that in ASP .NET projects using Visual Studio, you jave little or no control over the way the HTML is presented? Is this true? it seems a...
2
by: djc | last post by:
On the page_load event I am querying a database and binding data to some text boxes, list boxes, and a repeater control. When the page loads it uses the value of one of the database fields (status)...
6
by: Charles Law | last post by:
As a matter of practice, where would people put the following elements of object creation/initialisation: Create shared member objects Initialise shared member objects Create non-shared member...
0
by: bazzer | last post by:
hey, im trying to access a microsoft access database from an ASP.NET web application in visual basic 2003.NET. i get the following error when i try running it: Server Error in...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...

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.