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

Changing the properties of some controls on a form

I have this code:

for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is ValidationTextBox)
{
// Change the property of the control here.
}
}

ValidationTextBox is a control which derives from TextBox. It contain
some custom properties, among them: ValidValueColor.

As you see, I'm trying to change a property of all instances of
ValidationTextBox in my form. When I tried to do
this.Controls[i].ValidValueColor, I found out that the property wasn't
available. How can I access the custom properties from the
ValidationTextBox?

Thanks in advance!

Dan

Mar 10 '07 #1
3 1202
VJ
this.Controls[i] <--- returns type Control.. so you try something like
((ValidationTextBox)this.Controls[i]).ValidValueColor, that will work. To
avoid expection include type of check to ensuer that it is correct tpye.. if
(this.Control[i].GetType() == typeof(ValidationTextBox) )

Vijay

"Dan Soendergaard" <da*****@gmail.comwrote in message
news:11**********************@30g2000cwc.googlegro ups.com...
>I have this code:

for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is ValidationTextBox)
{
// Change the property of the control here.
}
}

ValidationTextBox is a control which derives from TextBox. It contain
some custom properties, among them: ValidValueColor.

As you see, I'm trying to change a property of all instances of
ValidationTextBox in my form. When I tried to do
this.Controls[i].ValidValueColor, I found out that the property wasn't
available. How can I access the custom properties from the
ValidationTextBox?

Thanks in advance!

Dan

Mar 10 '07 #2
On Mar 10, 4:33 am, "Dan Soendergaard" <dan1...@gmail.comwrote:
I have this code:

for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is ValidationTextBox)
{
// Change the property of the control here.
}
}

ValidationTextBox is a control which derives from TextBox. It contain
some custom properties, among them: ValidValueColor.

As you see, I'm trying to change a property of all instances of
ValidationTextBox in my form. When I tried to do
this.Controls[i].ValidValueColor, I found out that the property wasn't
available. How can I access the custom properties from the
ValidationTextBox?
Try this:

foreach (Control c in this.Controls)
{
ValidationTextBox vbox = c as ValidationTextBox
if (vbox != null)
{
// Change the property of the "vbox" control
here.
}
}

Mar 10 '07 #3
On Mar 10, 9:27 pm, "Bruce Wood" <brucew...@canada.comwrote:
On Mar 10, 4:33 am, "Dan Soendergaard" <dan1...@gmail.comwrote:
I have this code:
for (int i = 0; i < this.Controls.Count; i++)
{
if (this.Controls[i] is ValidationTextBox)
{
// Change the property of the control here.
}
}
ValidationTextBox is a control which derives from TextBox. It contain
some custom properties, among them: ValidValueColor.
As you see, I'm trying to change a property of all instances of
ValidationTextBox in my form. When I tried to do
this.Controls[i].ValidValueColor, I found out that the property wasn't
available. How can I access the custom properties from the
ValidationTextBox?

Try this:

foreach (Control c in this.Controls)
{
ValidationTextBox vbox = c as ValidationTextBox
if (vbox != null)
{
// Change the property of the "vbox" control
here.
}
}
Thanks, worked just fine!

Mar 11 '07 #4

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

Similar topics

8
by: deko | last post by:
I'm trying to find a way to set form/control properties programmatically. In a nut shell: 1. Open a database 2. Open a form in design view 3. Do something like this: For Each prp In...
2
by: ColinWard | last post by:
Hi. I have a form which has as its recordsource an SQL string. The SQL String is as follows: SELECT * from CONTACTS where false. this ensures that there is no data loaded in the form when the...
3
by: Gerry Abbott | last post by:
Hi all, Im wondering why the following will work Me.Controls("subnonstorePos").visible = False while Me.Controls("subnonstorePos").AllowEdits = False give me an 'property not support by...
4
by: Tony W | last post by:
Hi, I am trying to write a simple application to retrieve data from the Windows registry and insert it into textboxs on a windows form. So far I have one namespace containing two classess. ...
3
by: qwerty | last post by:
I´m new to ASP.Net. My workmate has some experience with it. He claimed that in ASP.Net working with frames is much simpler than it was ASP. I asked explanation but he couldn't give me such. (a...
1
by: Firewalker | last post by:
I am attempting to change the backColor property on the previously instantiated buttons FROM a listbox_doubleClick event. I thought it would be something like this: If...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
9
by: Dimsion | last post by:
Hi, How do i expose all my forms and it controls to other form in the project? I want to be able to add a form and some control on it, this then be available to all other forms. form1 click...
8
by: mike_solomon | last post by:
I have a button <input type="submit" name="Delete" value="Delete"> This code can not be changed I want to use Javascript to change the type I tried:
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: 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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.