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

Walk through self-made controls on a form?

Hello,
i've created my own TextBox based on standard .net-Textbox
as described by MS for my own properties of the textbox
and use it in another project.

I add the tx=new MyOwnControls.OwnTextbox by code on the
form, this works with me.controls.add(tx).

But when i try to access the tx in me.controls, i receive
an error: 'System.InvalidCastException'

for each tx in me.controls <---
...
next

How can i run through myOwnControls.OwnTextboxes in Form1?
Thanks!
Peter
Jul 19 '05 #1
2 1460
Hi!

The form contains more controls than the ones you have added. When you try
to go through the controls you must first check if the control is of
MyOwnControls.OwnTextbox type.

foreach (Control ctrl in this.Controls)
{
if (ctrl is (MyOwnControls.OwnTextbox))
{
MyOwnControls.OwnTextBox tb = (MyOwnControls.OwnTextBox)ctrl;
//Do what you want to do with the textbox here
}
}

I hope this helps

//Mikael

"dr.p.dietz" <pe***@nospam.de> wrote in message
news:0d****************************@phx.gbl...
Hello,
i've created my own TextBox based on standard .net-Textbox
as described by MS for my own properties of the textbox
and use it in another project.

I add the tx=new MyOwnControls.OwnTextbox by code on the
form, this works with me.controls.add(tx).

But when i try to access the tx in me.controls, i receive
an error: 'System.InvalidCastException'

for each tx in me.controls <---
..
next

How can i run through myOwnControls.OwnTextboxes in Form1?
Thanks!
Peter

Jul 19 '05 #2
I've tried several possibilities and found also your
solution.

..net seems to be very logical ;-)
Peter

-----Original Message-----
Hi!

The form contains more controls than the ones you have added. When you tryto go through the controls you must first check if the control is ofMyOwnControls.OwnTextbox type.

foreach (Control ctrl in this.Controls)
{
if (ctrl is (MyOwnControls.OwnTextbox))
{
MyOwnControls.OwnTextBox tb = (MyOwnControls.OwnTextBox)ctrl; //Do what you want to do with the textbox here
}
}

I hope this helps

//Mikael

"dr.p.dietz" <pe***@nospam.de> wrote in message
news:0d****************************@phx.gbl...
Hello,
i've created my own TextBox based on standard .net- Textbox as described by MS for my own properties of the textbox
and use it in another project.

I add the tx=new MyOwnControls.OwnTextbox by code on the
form, this works with me.controls.add(tx).

But when i try to access the tx in me.controls, i receive an error: 'System.InvalidCastException'

for each tx in me.controls <---
..
next

How can i run through myOwnControls.OwnTextboxes in Form1? Thanks!
Peter

.

Jul 19 '05 #3

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

Similar topics

11
by: rbt | last post by:
Is there an easy way to exclude binary files (I'm working on Windows XP) from the file list returned by os.walk()? Also, when reading files and you're unsure as to whether or not they are ascii...
7
by: rbt | last post by:
This function is intended to remove unwanted files and dirs from os.walk(). It will return correctly *IF* I leave the 'for fs in fs_objects' statement out (basically leave out the entire purpose of...
3
by: ina | last post by:
I want to walk a folder structor and group all the files by extention. Here is the code I put together is there a better way of doing this? <code> import os folderKey = "Folders" dicExt = {}...
7
by: KraftDiner | last post by:
The os.walk function walks the operating systems directory tree. This seems to work, but I don't quite understand the tupple that is returned... Can someone explain please? for root, dirs,...
9
by: silverburgh.meryl | last post by:
i am trying to use python to walk thru each subdirectory from a top directory. Here is my script: savedPagesDirectory = "/home/meryl/saved_pages/data" dir=open(savedPagesDirectory, 'r') ...
1
by: schellu | last post by:
i'm new to python script , i'm getting following error while executing AttributeError: class 'org.python.modules.os' has no attribute 'walk' my code is : class Client(Object): def...
2
by: gregpinero | last post by:
In the example from help(os.walk) it lists this: from os.path import join, getsize for root, dirs, files in walk('python/Lib/email'): print root, "consumes", print sum(), print "bytes in",...
4
by: Marcus Alves Grando | last post by:
Hello list, I have a strange problem with os.walk and threads in python script. I have one script that create some threads and consume Queue. For every value in Queue this script run os.walk()...
0
by: Jeff McNeil | last post by:
Your args are fine, that's just the way os.path.walk works. If you just need the absolute pathname of a directory when given a relative path, you can always use os.path.abspath, too. A couple...
4
by: Jeff Nyman | last post by:
Greetings all. I did some searching on this but I can't seem to find a specific solution. I have code like this: ========================================= def walker1(arg, dirname, names):...
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: 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
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.