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

Search for property in a control

Jac
Hey,

I extended different controls (textbox, combobox,..) with a property.

But now I will find that a control has that property. How can I do this?I
don't want to test if textbox, if combobox. I want to search on every control
(neither which control) if he has that property before I take any action.

if (ctr1.Propery1 == null) this is not correct.

foreach( Control ctr1 in this.groupBox1.Controls)
{
if (ctr1.Propery1 == null) continue;
if (ctr1.Propery1 == "BLA")
{
ctr1.Focus();
break;
}
}

Is there on a control a collection of the properties he has? Can I search in
that collection.
If the control has that property I have to do something.

Tkx,

Nov 17 '05 #1
3 1306
Hi,

you can you type.getproperty function that will return propertyinfo of
property based on property name..

System.Reflection.PropertyInfo pinf =
typeof(TextBox).GetProperty("property_name");
if (pinf != null)
{
// property exist
}

Regards,
Josip Habjan, Croatia
URL: http://www.habjansoftware.com

"Jac" <Ja*@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Hey,

I extended different controls (textbox, combobox,..) with a property.

But now I will find that a control has that property. How can I do this?I
don't want to test if textbox, if combobox. I want to search on every
control
(neither which control) if he has that property before I take any action.

if (ctr1.Propery1 == null) this is not correct.

foreach( Control ctr1 in this.groupBox1.Controls)
{
if (ctr1.Propery1 == null) continue;
if (ctr1.Propery1 == "BLA")
{
ctr1.Focus();
break;
}
}

Is there on a control a collection of the properties he has? Can I search
in
that collection.
If the control has that property I have to do something.

Tkx,

Nov 17 '05 #2
hi,
well you can use reflection as the other posted suggested, the bad thing is
that if you have several controls in your form and/or you do this check
several times it may impact your performance.

Another solution may be declaring an Interface where you define your
property, have the classes you write implement this interface and then you
can use the is operator, like this:

foreach(Control c in Controls)
if( c is IMyInterface )
{
((IMyInterface)c).Property = "XXXXXX";
}
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Jac" <Ja*@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Hey,

I extended different controls (textbox, combobox,..) with a property.

But now I will find that a control has that property. How can I do this?I
don't want to test if textbox, if combobox. I want to search on every
control
(neither which control) if he has that property before I take any action.

if (ctr1.Propery1 == null) this is not correct.

foreach( Control ctr1 in this.groupBox1.Controls)
{
if (ctr1.Propery1 == null) continue;
if (ctr1.Propery1 == "BLA")
{
ctr1.Focus();
break;
}
}

Is there on a control a collection of the properties he has? Can I search
in
that collection.
If the control has that property I have to do something.

Tkx,

Nov 17 '05 #3
Have you considered defining an Interface that these controls will
implement. Then you could simply test to see if the control "is"
implementing that interface and if so you'll know that the properties
outlined in the interface are present.

--
Tim Wilson
..Net Compact Framework MVP

"Jac" <Ja*@discussions.microsoft.com> wrote in message
news:5D**********************************@microsof t.com...
Hey,

I extended different controls (textbox, combobox,..) with a property.

But now I will find that a control has that property. How can I do this?I
don't want to test if textbox, if combobox. I want to search on every control (neither which control) if he has that property before I take any action.

if (ctr1.Propery1 == null) this is not correct.

foreach( Control ctr1 in this.groupBox1.Controls)
{
if (ctr1.Propery1 == null) continue;
if (ctr1.Propery1 == "BLA")
{
ctr1.Focus();
break;
}
}

Is there on a control a collection of the properties he has? Can I search in that collection.
If the control has that property I have to do something.

Tkx,

Nov 17 '05 #4

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

Similar topics

0
by: Colleyville Alan | last post by:
I have an app that looks up an id number and when a button is clicked, inputs the id # into a query. After running the query, I click a second button which grabs the client name rather than the id...
4
by: Lauren Wilson | last post by:
A2K I have a combo box that shows the content of a last name field from a table. I use it to locate records in the table form. I can open the form and locate several names quickly by placing...
5
by: DFS | last post by:
This works pretty well, and it's easy, but it's not the ultimate solution. The kludgey part is it uses a hidden field to incrementally capture the keystrokes in the visible field (because executing...
4
by: BenCoo | last post by:
Hello, In a Binary Search Tree I get the error : Object must be of type String if I run the form only with the "Dim bstLidnummer As New BinarySearchTree" it works fine. Thanks for any...
4
by: DavidB | last post by:
OK folks I am having a serious brain fart here and can't get the code to do what I really want done. I have a form that has a multi-table query as its data source. The data is dsplayed on the...
1
by: Reef81 | last post by:
Does anyone know a way to have the search parameters displayed in the query or report? For example, if I set up a parameter to search all entries in my table, is there a way to have the search...
5
by: Deano | last post by:
Perhaps this has been asked before but there might be some up to date thinking about this. I really need a better search function for my asset register. I allow assets to be entered and tracked...
4
by: bendlam | last post by:
I have a page that contains search criteria and when you click on the search button it causes a post back that populates a dataview on the same page. One of the gridview columns contains a link...
3
by: suek | last post by:
I have a table with over 4000 records to search upon, and the users don't like a combo box. So what I have been trying to do for the last twelve hours is do some code to get a text box to search. ...
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
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
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
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.